Rpm 方式安装
1、Rpm下载与版本选择地址:https://repo.mysql.com//
在本次安装中不需要从上面的地址下载,只需要查看并找到一个想要安装的 Mysql 版本,通过 yum localinstall 设置即可;
2、yum 安装:
如果 yum install 这一步特别慢,可以按如下方式操作:
进入 /var/cache/yum/x86_64/7/mysql80-community/packages,查看当前下载的缓存文件:
cd /var/cache/yum/x86_64/7/mysql80-community/packages
ll
# -rw-r--r-- 1 root root 49820920 Sep 25 04:58 mysql-community-client-8.0.22-1.el7.x86_64.rpm
# -rw-r--r-- 1 root root 262189056 Dec 18 00:02 mysql-community-server-8.0.22-1.el7.x86_64.rpm
到 国内镜像网站下载对应版本的 mysql-community-client 和 mysql-community-server 文件,然后覆盖掉 yum 下的缓存文件,即通过 xftp 上传 两个文件到 /var/cache/yum/x86_64/7/mysql80-community/packages
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/
正常安装过程如下:
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum module disable mysql
yum -y update
yum -y install mysql-community-server
3、修改配置
vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# Ezrealer set,email:Ezrealer@qq.com
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
bind-address = 0.0.0.0
#只能用IP地址检查客户端的登录,不用主机名
skip_name_resolve = 1
max_connections = 2000
default-time_zone='+8:00'
innodb_buffer_pool_size = 8G
thread_cache_size = 64
innodb_log_file_size = 2G
4、启动mysql 并修改密码
systemctl start mysqld.service
systemctl status mysqld.service
grep "password" /var/log/mysqld.log
mysql -uroot -p password
# 可选
set global validate_password_policy=0;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'testmysql';
5、设置远程连接权限
use mysql;
select host, user, authentication_string, plugin from user;
update user set host='%' where user='root';
FLUSH PRIVILEGES;
执行后用 navicat 连接发现报错:
1251-Client does not support authentication protocal requested by server ;consider upgrading mysql client
查找问题后发现:
MySQL8.0之前的版本密码加密规则:mysql_native_password,
MySQL8.0密码加密规则:caching_sha2_password
修改mysql加密规则
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新的密码';
FLUSH PRIVILEGES;
再测试,登录成功!
mysql 修改密码:
当使用
ALTER USER 'root'@'localhost' IDENTIFIED BY "new_password";
会报错 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,意思是新设定的密码不满足当前的安全策略需求,此时我们现查看一下默认的安全策略:
SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
validate_password.policy 是安全策略的等级,默认是 MEDIUM;
validate_password.length 是密码最短的长度;
此时我们可以调整密码的安全策略,如果想设置低于8位的密码,也可以调整最短密码长度:
set global validate_password.policy=LOW;
set global validate_password_length=6;
然后就可以修改密码了!
ALTER USER 'root'@'localhost' IDENTIFIED BY "new_password";