mysql8.0新增用戶及密碼加密規則修改

 

MySQL8.0已經發布GA版,當前最新GA版本爲8.0.12。雖然相對於以前版本,MySQL8.0沒有加入新元素,可是,通過代碼重構,MySQL8.0的優化器更增強大,同時也有一些新特性,如支持索引隱藏等。mysql

可是,MySQL新版本中也有不少與先前版本不同的地方,好比在用戶建立上就有不少變化。linux

 

1. 用戶建立sql

 建立用戶的操做已經不支持grant的同時建立用戶的方式,需先建立用戶再進行受權bash

mysql> grant all on *.* to 'admin'@'%' identified by 'admin123'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'admin123'' at line 1 mysql> create user  'admin'@'%' identified by 'admin123'; Query OK, 0 rows affected (0.06 sec) mysql> grant all on *.* to 'admin'@'%' ; Query OK, 0 rows affected (0.04 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

 

 2. 用戶登陸1微信

當用戶密碼含有字母或數字外的特殊符號登陸時,原先使用雙引號或單引號均可以登陸,但在mysql8.0登陸時遇到問題,以下socket

[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p"root!@#123" --socket=/data/mysql/mysql3310/tmp/mysql3310.sock -bash: !@#123": event not found
[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'root!@#123' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.0.12 MySQL Community Server - GPL

3.低版本客戶端登陸異常ide

 錯誤號碼 2058:Plugin caching_sha2_password could not be loaded優化

出現這個緣由是mysql8.0 以前的版本中加密規則是mysql_native_password,而在mysql8以後,加密規則是caching_sha2_password, 解決此問題方法有兩種,一種是升級客戶端驅動,一種是把mysql用戶登陸密碼加密規則還原成mysql_native_password。加密

若是修改用戶密碼加密規則可以使用以下方式:spa

1). 修改加密方式:

-- 修改密碼爲用不過時
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.02 sec) -- 修改密碼並指定加密規則爲mysql_native_password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.01 sec) -- 刷新權限
mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>

修改完畢後再次登陸便可成功

 

 

2).使用高版本客戶端

linux低版本客戶端登陸時也會出現此狀況,所以需使用高版本的客戶端

[root@gjc18 lib]# mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/local/mysql/lib/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory [root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 26 Server version: 8.0.12 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

除了密碼插件調整外,MySQL8.0其餘幾個主要的新密碼策略有:

  • 支持密碼過時策略,須要週期性修改密碼
  • 增長曆史密碼校驗機制,防止近幾回的密碼相同(次數能夠配置)
  • 修改密碼是須要驗證舊密碼,防止被篡改風險
  • 支持雙密碼機制,即新密碼與修改前的舊密碼同時可使用,且能夠選擇採用主密碼仍是第二個密碼
  • 增長密碼強度約束,避免使用弱密碼

 

 

 

耿小廚已開通我的微信公衆號,想進一步溝通或想了解其餘文章的同窗能夠關注我

相關文章
相關標籤/搜索