1. 下载MysqL的repo源
CentOS7的yum源中默认好像是没有MysqL的。为了解决这个问题,我们要先下载MysqL的repo源。
wget http://repo.MysqL.com/MysqL-community-release-el7-5.noarch.rpm
2. 安装MysqL-community-release-el7-5.noarch.rpm包
sudo 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。
3. 安装MysqL
$ sudo yum install MysqL-server
根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。
4. 重置密码
重置密码前,首先要登录
$ MysqL -u root
登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MysqL server through socket ‘/var/lib/MysqL/MysqL.sock‘ (2),原因是/var/lib/MysqL的访问权限问题。下面的命令把/var/lib/MysqL的拥有者改为当前用户:
$ sudo chown -R openscanner:openscanner /var/lib/MysqL
然后,重启$ service MysqLd restart登录重置密码:
$ MysqL -u root
MysqL > use MysqL;
MysqL > update user set password=password('123456') where user='root';
MysqL > exit;
5. 运行远程访问
UPDATE user SET Host='%' WHERE User='root' flush privileges;
或者
grant all privileges on *.* to 创建的用户名 @"%" identified by "密码";
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;