1、创建mysql目录:
mkdir /usr/local/mysql
cd /usr/local/mysql
2、下载rpm包:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
3、安装rpm:
yum -y install mysql57-community-release-el7-10.noarch.rpm
4、安装mysql服务:
yum -y install mysql-community-server
5、查看mysql的默认登陆密码:
grep "password" /var/log/mysqld.log
如图所示
6、登录mysql,输入默认密码:
mysql -uroot -p
7、修改密码的复杂度:
set global validate_password_policy=LOW;
8、重新设置密码:
alter user 'root'@'localhost' IDENTIFIED BY 'password';
9、查询:
show database;
10、开启远程访问,“%”是值所有的ip都可以,“password”是远程访问的密码
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
如果只允许某一台,将“%”修改为对应的ip
grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'password' with grant option;
11、刷新配置:
flush privileges;
12、开放3306端口:
systemctl start firewalld #启动防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent #开放端口
firewall-cmd --reload #配置立即生效
13、远程连接测试: