1.下载地址:MySQL
# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
如果没有wget命令,则需要安装:
yum -y install wget
2.安装mysql8:
# yum -y localinstall mysql80-community-release-el7-1.noarch.rpm
# yum -y install mysql-community-server
3.启动MySQL服务:
# systemctl start mysqld
4.设置MySQL开机启动:
# systemctl enable mysqld
# systemctl daemon-reload
5.修改初始密码:mysql安装完成后,在/var/log/mysqld.log文件中生成一个临时的MySQL密码:
(如果不修改初始密码,MySQL不能正常使用,输入MySQL命令会报错:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.)
# grep "temporary password" /var/log/mysqld.log
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost:Qd0C9iersB+X
# mysql -u root -pQd0C9iersB+X
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ssssAAA@1234';
Query OK, 0 rows affected (0.25 sec)
6.配置默认编码为utf-8:
vi /etc/my.cnf
在[mysql]下添加编码配置:
character_set_server=utf8
init_connect=‘SET NAMES utf8’
保存后重启MySQL服务:
systemctl restart mysqld
7.允许远程登录:
iptables -L -n //查看3306端口是否已开启;
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT //开启3306端口