使用于CentOS 7
更新YUM源:
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
安装MySQL:
yum -y install mysql-community-server
启动MySQL服务:
systemctl start mysqld
设置MySQL服务开机自启动:
systemctl enable mysqld
查看root的默认密码:
grep 'temporary password' /var/log/mysqld.log
执行代码如下:
2020-04-08T08:12:07.893939Z 1 [Note] A temporary password is generated for root@localhost: xvlo1lZs7>uI
运行以下代码对MySql进行安全配置:
mysql_secure_installation
第一次进行安全配置:
mysql_secure_installation =》 输入root的密码
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次输入新密码
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y #是否继续操作,输入Y
后续的安全配置:
mysql_secure_installation =》 输入root的密码
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y #是否继续操作,输入Y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y
遇到的问题?
1.外网连接失败
解决1:
开放3306端口,{注:如果是(阿里云/腾讯云)服务器则需要配置安全组}
/sbin/iptables -I INPUT -p tcp --dport 端口 -j ACCEPT
解决2:
原因是root权限未开放外网连接,连接进入数据库,执行如下代码
use mysql;
update user set host = '%' where user = 'root';
flush privileges;