1.下载
在自定义目录下安装:
wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
2.安装
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
如果报错:
mysql-community-common-5.7.43-1.el7.x86_64.rpm 的公钥尚未安装
解决方案:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重行执行安装命令!
3.启动mysql
systemctl start mysqld
4.查看是否已启动
systemctl status mysqld
5.查看初始化生成的root密码
grep 'temporary password' /var/log/mysqld.log
例:
A temporary password is generated for root@localhost: oLuPXywHY4<P
密码:oLuPXywHY4<P
6.进入数据库
输入刚才查询出来的密码
mysql -uroot -p
7.修改密码
SET PASSWORD=PASSWORD('Admin123!');
如果报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
设置密码的验证强度等级:
set global validate_password_policy=LOW; # 强度等级
set global validate_password_length=6; # 密码最低位数
8.设置可以远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Admin123!' WITH GRANT OPTION;
9.退出
exit;
10.mysql 编码配置
[client]、[mysql] 需要手动创建,[mysqld]在节点末尾追加即可
vim /etc/my.cnf
[mysqld]
character-set-client-handshake=FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
11.重启
systemctl restart mysqld
11.设置开机启动
systemctl enable mysqld
systemctl daemon-reload
文章评论