linux安装mysq5.6

  1. 下载mysql的repo源
		wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
  1. 安装mysql-community-release-el7-5.noarch.rpm包
   rpm -ivh mysql-community-release-el7-5.noarch.rpm

	命令执行完毕,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc /yum.repos.d/mysql-community-source.repo。
  1. 安装mysql
 yum install mysql-server
  1. 重置密码
 mysql -u root;
 use mysql;
 update user set password=password('123456') where user='root';

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。
执行: chown -R root:root /var/lib/mysql;
 		   service mysqld restart;
  1. 需要更改权限才能实现远程连接MYSQL数据库
	mysql -h localhost -uroot -p;
	Enter password: ******
	use mysql; (此DB存放MySQL的各种配置信息)
  select host, user, password from user;
+-----------+------+-------------------------------------------+
| host       | user | password                                   |
+-----------+------+-------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost |       |                                            |
+-----------+------+-------------------------------------------+
4 rows in set (0.01 sec)

由此可以看出,只能以localhost的主机方式访问。

解决方法:
Grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;
(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,)
mysql> flush privileges; (运行此句才生效,或者重启MySQL)
再次查看。。
mysql> select host, user, password from user;
±----------±-----±------------------------------------------+
| host | user | password |
±----------±-----±------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost | | |
| % | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
±----------±-----±------------------------------------------+
4 rows in set (0.01 sec)

安装完毕!

你可能感兴趣的:(mysql,Linux,Centos)