Mysql完全卸载
删除Mysql:
yum remove mysql mysql-server mysql-libs mysql-server
;find / -name mysql
将找到的相关东西delete掉(比如rm -rf /var/lib/mysql
);rpm -qa|grep mysql
(查询出来的东东yum remove
掉)rm /etc/my.cnf
然后查看是否还有mysql软件:
rpm -qa|grep mysql
如果存在的话,继续删除即可。
安装Mysql
#yum install mysql
#yum install mysql-server
#yum install mysql-devel
安装mysql和mysql-devel都成功,但是安装mysql-server失败,如下:
[root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.sina.cn
* extras: mirrors.sina.cn
* updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do
查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
解决办法如下:
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
安装成功后重启mysql服务。
# service mysqld restart
初次安装mysql,root账户没有密码。如果登陆不成功的话,设置vi /etc/my.cnf
,然后在最后添加一行skip-grant-tables
即可。
[root@yl-web yl]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.01 sec)
mysql>
设置密码:
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';