安装MySQL
# 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# 利用 Yum Repository来安装,Mysql版本5.7.14
yum -y install mysql57-community-release-el7-10.noarch.rpm
# 开始安装MySQL服务器
yum -y install mysql-community-server
# 启动MySQL
systemctl start mysqld.service
# 查看MySQL运行状态
systemctl status mysqld.service
# 查看默认root用户的密码
grep "password" /var/log/mysqld.log
# 登录MySQL
mysql -uroot -p
# 修改root账号密码,新密码需要包含大小写数字符号才能通过安全验证
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
# 开启远程访问连接
mysql> grant all privileges on *.* to 'root'@'10.0.21.%' identified by 'password' with grant option;
# 刷新配置
mysql> flush privileges;
# 修改MySQL编码,默认的MySQL server的编码是latin1。修改编码需要退出MySQL编辑/etc/my.cnf文件
# 查看MySQL编码
mysql> status;
MySQL运行状态查看:
查看MySQL编码:
修改MySQL编码
# 如果防火墙开着则需要关闭防火墙或者开放3306端口
# 查看防火墙状态
firewall-cmd --state
#关闭防火墙
systemctl stop firewalld.service
# 禁止开机自启动防火墙
systemctl disable firewalld.service
# 不关闭防火墙的话,开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重新载入防火墙配置
firewall-cmd --reload
# 修改MySQL编码,在 [mysqld] 和 [client] 下面分别新增如下编码配置
vim /etc/my.cnf
[mysqld]
# 设置MySQL server编码格式
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
[client]
default-character-set=utf8mb4
# 重启MySQL
service mysqld restart
# 登录MySQL,再次用status 命令查看编码,就能看到编码已经修改为utf8