配置yum源
下载地址
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
上传到服务器,配置yum源
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
检查mysql源是否安装成功
yum repolist all | grep mysql
禁用8.0,启用5.7
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
确认是否执行成功
yum repolist enabled | grep mysql
安装mysql
遇到提示按y+回车
sudo yum install mysql-community-server
启动mysql
sudo service mysqld start
查看状态
systemctl status mysqld
设置开机启动
systemctl enable mysqld
systemctl daemon-reload
修改root密码
修改密码
查看密码
sudo grep 'temporary password' /var/log/mysqld.log
修改密码策略
登录
mysql -uroot -p
回车输入密码
mysql控制台内
修改密码策略
set global validate_password_policy=0;
set global validate_password_length=1;
修改
mysql控制台内
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
允许远程登录
mysql控制台内
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
退出mysql
mysql控制台内
mysql> exit
修改默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下:
vi /etc/my.cnf
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
![](https://img-blog.csdnimg.cn/20210625110731485.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI1MjgzNzA5,size_16,color_FFFFFF,t_70#pic_center
重启mysql服务
service mysqld restart