王海庆的云笔记

CentOS7采用yum方式安装mysql8.0(修改存储路径)


关闭防火墙

systemctl stop firewalld
systemctl disable firewalld
sed -i -e  's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0


换成阿里云的源

rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

yum clean all
yum makecache fast -y


安装

curl -L -o mysql80-community-release-el7-1.noarch.rpm https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum -y install mysql80-community-release-el7-1.noarch.rpm
yum install -y mysql-community-server


创建文件夹

mkdir -p /data/mysql


追加配置文件/etc/my.cnf

cat >>  /etc/my.cnf  << "EOF"

character-set-server=utf8 
collation-server=utf8_general_ci 
#character-set-server=utf8mb4
#collation-server=utf8mb4_general_ci 
lower_case_table_names=1 
max_connections=10240
open_files_limit=10240
max_connect_errors=10240
max_allowed_packet=10M
port=3306

# 设置密码的验证强度等级,这里开启这个参数会报错
# validate_password_policy=LOW

# zkxy使用此字段
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]
socket=/data/mysql/mysql.sock

EOF


修改如下路径/etc/my.cnf

sed -i 's#^datadir.*#datadir=/data/mysql#g'  /etc/my.cnf
sed -i 's#^socket.*#socket=/data/mysql/mysql.sock#g'  /etc/my.cnf


启动服务

systemctl restart mysqld 
systemctl enable mysqld 
systemctl status mysqld


修改密码

# 在日志中获取密码
grep 'temporary password' /var/log/mysqld.log

# 登录mysql,密码是上一步日志获取的
mysql -uroot -p

# 修改root密码
ALTER user root@localhost identified by 'Star*1234';

use mysql;
update user set host = '%' where user = 'root';
select host, user, authentication_string, plugin from user;

# 刷新立即生效
flush privileges;


采用旧版本的客户端,因为密码插件的问题,可能不能连接。

mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password, 

251-Client does not support authentication protocol requested by server; consider upgrading My SQL client


把mysql用户登录密码还原成mysql_native_password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Star*1234';


如果mysql启动失败,可能是有哪位没有关闭防火墙和selinux,具体可以查看mysql的日志

tail -n500 /var/log/mysqld.log|grep -E 'Warning|ERROR'

文章最后更新时间: 2021-12-03 23:29:55