【Mysql】Centos8.2 安裝 Mysql 8.0

Ezrealer發表於2020-12-08

Rpm 方式安裝

1、Rpm下載與版本選擇地址:https://repo.mysql.com//

在本次安裝中不需要從上面的地址下載,只需要選擇一個合適的版本,通過 dnf localinstall 設定即可;

2、dnf 方式安裝:

如果 dnf install 這一步特別慢,可以通過 國內映象下載對應版本的 mysql-community-sercer,然後覆蓋掉 dnf 的對應快取(/var/dnf/mysql/)。

http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/

dnf localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

dnf module disable mysql

dnf -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;

再測試,登入成功!

相關文章