MySQL5.7.11 -- 嚴格的密碼要求

urgel_babay發表於2016-02-29
2016.02.27
今天接著學習MySQL,前天安裝完了MySQL 5.7.11,在此基礎進一步瞭解新版本MySQL的各項改變。

5.7.11對密碼有了更嚴格的要求,分為LOW,MEDIUM,STRONG三個等級,對應要求如下:
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

由於前天安裝MySQL的時候,是按照以往的5.6經驗流程,所以密碼設定都是比較一般,現在開始按照5.7.11的要求設定密碼
  1. [root@zhangMySQL5711 bin]# ./mysql_secure_installation         //此檔案在/usr/local/mysql/bin 目錄下
  2. Securing the MySQL server deployment.

  3. Connecting to MySQL server using password in '/root/.mysql_secret'      //提示使用安裝時,MySQL提供的隨機密碼
  4. Error: Access denied for user 'root'@'localhost' (using password: YES)
  5. [root@zhangMySQL5711 bin]# more /root/.mysql_secret
  6. # Password set for user 'root@localhost' at 2016-02-24 17:49:00
  7. E>_iG6u+<%dh
  8. [root@zhangMySQL5711 bin]# ./mysql_secure_installation --help             //help 檢視一下相關的引數選項,這裡不多解釋每一項,平時用到的也就那麼熟悉的幾項
  9. ./mysql_secure_installation Ver 5.7.11, for Linux on x86_64
  10. Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.

  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.
  14. MySQL Configuration Utility.Usage: ./mysql_secure_installation [OPTIONS]
  15.   -?, --help Display this help and exit.
  16.   -h, --host=name Connect to host.
  17.   -p, --password[=name]
  18.                       Password to connect to the server. If password is not
  19.                       given it's asked from the tty.
  20.   -P, --port=# Port number to use for connection or 0 for default to, in
  21.                       order of preference, my.cnf, $MYSQL_TCP_PORT,
  22.                       /etc/services, built-in default (3306).
  23.   --protocol=name The protocol to use for connection (tcp, socket, pipe,
  24.                       memory).
  25.   -S, --socket=name Socket file to be used for connection.
  26.   --ssl-mode=name SSL connection mode.
  27.   --ssl Deprecated. Use --ssl-mode instead.
  28.                       (Defaults to on; use --skip-ssl to disable.)
  29.   --ssl-verify-server-cert
  30.                       Deprecated. Use --ssl-mode=VERIFY_IDENTITY instead.
  31.   --ssl-ca=name CA file in PEM format.
  32.   --ssl-capath=name CA directory.
  33.   --ssl-cert=name X509 cert in PEM format.
  34.   --ssl-cipher=name SSL cipher to use.
  35.   --ssl-key=name X509 key in PEM format.
  36.   --ssl-crl=name Certificate revocation list.
  37.   --ssl-crlpath=name Certificate revocation list path.
  38.   --tls-version=name TLS version to use, permitted values are: TLSv1, TLSv1.1
  39.   -u, --user=name User for login if not root.
  40.   -D, --use-default Execute with no user interactivity

  41. Default options are read from the following files in the given order:
  42. /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
  43. The following groups are read: mysql_secure_installation mysql client
  44. The following options may be given as the first argument:
  45. --print-defaults Print the program argument list and exit.
  46. --no-defaults Don't read default options from any option file,
  47.                         except for login file.
  48. --defaults-file=# Only read default options from the given file #.
  49. --defaults-extra-file=# Read this file after the global files are read.
  50. --defaults-group-suffix=#
  51.                         Also read groups with concat(group, suffix)
  52. --login-path=# Read this path from the login file.

  53. Variables (--variable-name=value)
  54. and boolean options {FALSE|TRUE} Value (after reading options)
  55. --------------------------------- ----------------------------------------
  56. host localhost
  57. port 0
  58. socket (No default value)
  59. ssl TRUE
  60. ssl-verify-server-cert FALSE
  61. ssl-ca (No default value)
  62. ssl-capath (No default value)
  63. ssl-cert (No default value)
  64. ssl-cipher (No default value)
  65. ssl-key (No default value)
  66. ssl-crl (No default value)
  67. ssl-crlpath (No default value)
  68. tls-version (No default value)
  69. user root
  70. use-default FALSE
  71. [root@zhangMySQL5711 bin]# ./mysql_secure_installation -uroot -p                // 嘗試登入,使用安裝後我自己密碼:zhangmysql
  72. Enter password:

  73. Securing the MySQL server deployment.

  74. Error: Access denied for user 'root'@'localhost' (using password: YES)          //登入失敗,說明使用mysql_secure_installation方式登入,原來的密碼已經不能使用了
  75. [root@zhangMySQL5711 bin]# ./mysql_secure_installation -uroot -p                //再次登入,使用安裝是MySQL自己提供的隨機密碼:E>_iG6u+<%dh     登入成功!
  76. Enter password:

  77. Securing the MySQL server deployment.


  78. VALIDATE PASSWORD PLUGIN can be used to test passwords                        //密碼驗證外掛,為了提高安全性,需要驗證密碼
  79. and improve security. It checks the strength of password                      // 它會檢查密碼的強度
  80. and allows the users to set only those passwords which are                    //只允許使用者設定足夠安全的密碼
  81. secure enough. Would you like to setup VALIDATE PASSWORD plugin?              //提示安裝密碼驗證外掛

  82. Press y|Y for Yes, any other key for No: y

  83. There are three levels of password validation policy:                      //三個等級的驗證策略

  84. LOW Length >= 8                                                             //最小長度大於等於8個字元
  85. MEDIUM Length >= 8, numeric, mixed case, and special characters             //數字,字母,特殊字元 混合,具體的應該是至少1個數字,1個字母,1個特殊字元,長度不超過32個字元
  86. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file   //  最嚴格,加上了,字典檔案

  87. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2                      //這裡我選擇2 MEDIUM
  88. Using existing password for root.

  89. Estimated strength of the password: 50                                   //這裡也是密碼強度的評級
  90. Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

  91. New password:                                                        //我這裡輸入的是:Zhangmysql57

  92. Re-enter new password:

  93. Estimated strength of the password: 50
  94. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y     //提示要使用剛剛輸入的密碼嗎?
  95.  ... Failed! Error: Your password does not satisfy the current policy requirements                   //外掛驗證不透過,不符合當前安全要求級別

  96. New password:                                                        //我這裡輸入的是:Zhangmysql_57

  97. Re-enter new password:

  98. Estimated strength of the password: 100
  99. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
  100. By default, a MySQL installation has an anonymous user,               //預設情況下,MySQL有一個匿名使用者,
  101. allowing anyone to log into MySQL without having to have              //這個匿名使用者,不必有一個使用者為他們建立匿名使用者允許任何人登入到MySQL,
  102. a user account created for them. This is intended only for            //這只是為了方便測試使用
  103. testing, and to make the installation go a bit smoother.
  104. You should remove them before moving into a production                //在正式環境使用的時候,建議你移除它
  105. environment.

  106. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y                //提示移除匿名使用者
  107. Success.

  108. Normally, root should only be allowed to connect from                        //一般情況下,root使用者只允許使用"localhost"方式登入,
  109. 'localhost'. This ensures that someone cannot guess at                       // 以此確保,不能被某些人透過網路的方式訪問
  110. the root password from the network.

  111. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n          //

  112.  ... skipping.
  113. By default, MySQL comes with a database named 'test' that                      //預設情況下,MySQL資料庫中有一個任何使用者都可以訪問的test庫,
  114. anyone can access. This is also intended only for testing,                     //這也僅僅是為了測試
  115. and should be removed before moving into a production                          // 在正式環境下,應該移除掉
  116. environment.


  117. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  118.  - Dropping test database...
  119. Success.

  120.  - Removing privileges on test database...
  121. Success.

  122. Reloading the privilege tables will ensure that all changes                           //重新整理許可權表,以確保所有的修改可以立刻生效
  123. made so far will take effect immediately.

  124. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  125. Success.

  126. All done!
  127. [root@zhangMySQL5711 bin]
到此,密碼修改完成了,現在去嘗試登入,看是否是如此。

  1. [root@zhangMySQL5711 ~]# mysql -uroot -p                              //使用第一次安裝時候的密碼:zhangmysql
  2. Enter password:
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  4. [root@zhangMySQL5711 ~]# mysql -uroot -p                              //使用 安裝MySQL要求設定的密碼 :Zhangmysql_57
  5. Enter password:
  6. Welcome to the MySQL monitor. Commands end with ; or \g.
  7. Your MySQL connection id is 17
  8. Server version: 5.7.11 Source distribution

  9. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

  10. Oracle is a registered trademark of Oracle Corporation and/or its
  11. affiliates. Other names may be trademarks of their respective
  12. owners.

  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  14. mysql> show databases;                         //顯示沒有了test庫
  15. +--------------------+
  16. | Database |
  17. +--------------------+
  18. | information_schema |
  19. | mysql |
  20. | performance_schema |
  21. | sys |
  22. +--------------------+
  23. 4 rows in set (0.00 sec)

  24. mysql> select user ,host from mysql.user;                     //root使用者只有"localhost"
  25. +-----------+-----------+
  26. | user | host |
  27. +-----------+-----------+
  28. | zhang | % |
  29. | mysql.sys | localhost |
  30. | root | localhost |
  31. | zhang | localhost |
  32. +-----------+-----------+
  33. 4 rows in set (0.00 sec)

  34. mysql>  GRANT ALL PRIVILEGES ON *.* TO root@"%" ;                         
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    mysql>  GRANT ALL PRIVILEGES ON *.* TO root@"%"  IDENTIFIED BY "Zhangmysql_57";
    Query OK, 0 rows affected, 1 warning (0.00 sec)
可以確定,上面的步驟全部生效了,其實說白了,就是要把密碼設定的複雜一些,就這!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30936525/viewspace-2016528/,如需轉載,請註明出處,否則將追究法律責任。

相關文章