CentOS 7.0yum安装MySQL

1.下载mysql的repo源

1
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2.安装mysql-community-release-el7-5.noarch.rpm包

1
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:

1
/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo

3.安装mysql

1
$ sudo yum install mysql-server

根据提示安装就可以了,不过安装完成后没有密码,需要重置密码

4.重置mysql密码

1
$ mysql -u root
1
注意:登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘

原因是/var/lib/mysql的访问权限问题

5.下面的命令把/var/lib/mysql的拥有者改为当前用户:

1
$ sudo chown -R root:root /var/lib/mysql

6.重启mysql服务

1
$ service mysqld restart

7.接下来登录重置密码:

1
2
3
4
$ mysql -u root  //直接回车进入mysql控制台
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;
-------------本文结束感谢您的阅读-------------
0%