-
安装Mysql
① wget https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
② sudo rpm -Uvh platform-and-version-specific-package-name.rpm(下载到根目录的安装文件名)
③ yum install -y mysql-community-server
④ 启动:service mysqld start
⑤ 查看状态:service mysqld status
-
修改临时密码
① 查看临时密码:grep ‘temporary password’ /var/log/mysqld.log
② 登录mysql:mysql -u root -p
③ 修改密码:ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘root123’;(MySql8要求密码复杂度,大小写字母+数字+特殊字符),如果要修改密码策略,使用以下语句:
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1; -
修改远程连接权限(允许远程主机登录MySql)
注意: MySQL 安装完成后只支持 localhost 访问,我们必须设置一下才可以远程访问。
输入以下命令发现均报错:
mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘Root123!’ WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘IDENTIFIED BY ‘Root123!’ WITH GRANT OPTION’ at line 1
mysql> GRANT ALL ON . TO ‘root’@’%’;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant all privileges on . to ‘root’@’%’ with grant option;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
① 可执行如下命令修改root远程连接权限:
mysql> update user set host = “%” where user=‘root’;
② 打开3360端口
查看状态:systemctl status firewalld
开启firewalld(如果不是running状态):systemctl start firewalld
开启端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新载入:firewall-cmd --reload
查看:firewall-cmd --zone=public --query-port=3306/tcp
删除端口:firewall-cmd --zone=public --remove-port=3306/tcp --permanent