安装之前先安装基本环境:yum install -y perl perl-Module-Build net-tools autoconf libaio numactl-libs
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619115150224-1522952457.png)
# 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm /installpackage
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619115808680-731936661.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619120328692-1732037550.png)
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619120606307-485846431.png)
修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.7版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619121052650-880414696.png)
安装MySQL
yum install mysql-community-server
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619122849206-1033355145.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619122922090-1154669673.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619122946783-1437961443.png)
启动MySQL服务
systemctl start mysqld
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619123202379-828899802.png)
查看MySQL的启动状态
systemctl status mysqld
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619123304897-593239651.png)
开机启动
systemctl enable mysqld
systemctl daemon-reload
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619123438693-30865719.png)
修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
grep 'temporary password' /var/log/mysqld.log
#本次安装没有初始的密码,直接回车登录MySQL
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619123956687-1944190842.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619124021530-1871650214.png)
set password for 'root'@'localhost'=password('admin');
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619124345843-1861155136.png)
配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
character_set_server=utf8
init_connect='SET NAMES utf8'
show variables like '%character%';
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619125128644-1252063340.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619125153817-1282578930.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619125315122-1122630965.png)
添加远程登录用户
1.在连接服务器后,操作mysql系统数据库
mysql -u root -p
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130208302-1350228376.png)
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130305752-97515926.png)
查询用户表命令:select User,authentication_string,Host from user;
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130434585-981842155.png)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin';
这里的admin为你给新增权限用户设置的密码,%代表所有主机,也可以具体到你的主机ip地址。
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130641700-110511009.png)
flush privileges;
这一步一定要做,不然无法成功! 这句表示从mysql数据库的grant表中重新加载权限数据。因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130813145-2081144092.png)
再次查询用户表命令:select User,authentication_string,Host from user;
![](https://img2018.cnblogs.com/blog/1020928/201906/1020928-20190619130906643-984914080.png)