wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum -y install mysql-server
#尝试开启mysql服务
systemctl start mysqld
#查看服务状态
systemctl status mysqld
#关闭服务进行字符集配置
systemctl stop mysqld
vim /etc/my.cnf
-------------------------------------------
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
datadir=/opt/software/mysql57/data
-------------------------------------------
#命令行生成并获取临时密码
grep 'temporary password' /var/log/mysqld.log
2021-05-25T04:14:58.813447Z 1 [Note] A temporary password is generated for root@localhost: pj7d2lW=,7n*
#利用临时密码登录,并修改密码
mysql -u root -ppj7d2lW
#如果 /var/log/mysqld.log 中不存在初始化临时密码
#通过以下途径设置免密登录
#1、关闭Mysql服务
systemctl stop mysqld
#2、修改匹配文件启动免密登录
vim /etc/my.cnf
[mysqld]
skip-grant-tables
#3、启动mysql服务
systemctl start mysqld
#4、免密登录
mysql #回车
#5、立即修改本地访问root账号密码后退出mysql
use mysql;
update user set password/authentication_string=password('1234') where user='root';
exit;
#6、关闭mysql服务,删除配置信息skip-grant-tables
#再次启动mysql服务后可以使用之前修改的密码正常登录
#7、必须在进行其他操作前修改符合密码策略要求的密码
alter user 'root'@'localhost' identified by '@12A3a4pola';
#7.1、如果需要修改密码难度等级
set global validate_password_policy=0;
flush privileges;
#7.2、再次重置密码:最小长度8
alter user 'root'@'localhost' identified by '12345678';
#8、启动远程访问
grant all on *.* to root@'%' identified by 'kb12kb12';