CentOS7 install MySQL5.7

处理其他DB

首先执行以下命令处理yum上的其他分发类型的数据库。

yum list installed mariadb\*
yum list installed Percona\*

执行以上命令若有显示,请执行以下命令。

yum-config-manager --disable mariadb
yum-config-manager --disable percona-release

卸载其他分发数据库

yum remove MariaDB-common MariaDB-compat MariaDB-server
yum remove Percona-Server-client-55 Percona-Server-server-55 \
Percona-Server-shared-55.i686 percona-release

安装mysql的yum源

访问以下链接获取到red hat的rpm文件地址,并使用wget命令下载到服务器上。

https://dev.mysql.com/downloads/repo/yum/

也可以直接下载后使用ftp上传到服务器上。

安装yum源

yum localinstall mysql*****.noarch.rpm

检查mysql源

yum repolist enabled | grep "mysql.*-community.*"

安装mysql

yum install mysql-community-server

启动mysql

systemctl start mysqld

查看启动状态

systemctl status mysqld

设置开机启动

systemctl enable mysqld
systemctl daemon-reload

查看生成的mysql root密码

grep 'temporary password' /var/log/mysqld.log

root@localhost:后面的就是mysql密码,复制下来即可。

登陆mysql

mysql -u root -p

粘贴密码。

设置root用户密码(请设置符合mysql57要求的高强度密码)

set password for root@localhost = password('your password!!');
use mysql;

设置root用户可远程连接

update user set host = '%' where user ='root';

刷新用户权限

flush privileges;

在mysql中执行以下命令设置数据库编码(直接复制所有命令然后回车确认一次即可)

set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;

查看mysql编码

show variables like 'character%';

显示如下内容代表成功

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

保存后重启MySQL服务

service mysqld.service restart

添加防火墙端口

firewall-cmd --permanent --zone=public --add-port=3306/tcp

重载防火墙配置

firewall-cmd --reload