1. 程式人生 > 實用技巧 >解決mysql 8.0.20版本“this user requires mysql native password authentication”問題

解決mysql 8.0.20版本“this user requires mysql native password authentication”問題

經過查詢後得知是MySQL 8的使用者密碼加密方式導致,MySQL 8 的預設密碼加密方式為 :caching_sha2_password

之前常用的低版本的密碼加密方式為:mysql_native_password,所以需要把MySQL 8中的使用者密碼加密方式修改為常用的加密方式:mysql_native_password

直接修改配置檔案,在mysql的配置檔案中加入如下配置:

default-authentication-plugin=mysql_native_password

改完配置檔案後,重啟mysql,重新連線資料庫成功,可正常操作。

完整的配置檔案內容如下:

[root@xxxxxr]$ cat /etc/my.cnf
[mysqld]
default-authentication-plugin=mysql_native_password
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
bind-address=x.x.x.x
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
#socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
##character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/data/mysql/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
pid-file=/data/mysql/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d