解決mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication錯誤

來源:互聯網
上載者:User

mysqlnd是個好東西。不僅可以提高與mysql資料庫通訊的效率,而且也可以方便的設定一些逾時。如,連線逾時,查詢逾時。
但是,使用mysqlnd的時候,有個地方需要注意。就是服務端的密碼格式不能使用舊的16位的儲存格式,而要使用新的41位的儲存格式。
如果,服務端的密碼格式是16位,那麼就會報錯。資訊如下:

Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD(‘your_existing_password’). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file’ in /home/hailong.xhl/test.php:8

如何查看自己的密碼是否符合要求,so easy。

mysql> select user,length(password) from mysql.user;
+--------------+------------------+
| user         | length(password) |
+--------------+------------------+
| demo         |               16 |
| demo         |               16 |
+--------------+------------------+
上面的密碼是舊的16位格式。如果想改成新的41位格式,通過以下命令就可以。
mysql>UPDATE mysql.user SET Password = PASSWORD('demo') WHERE user = 'demo';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> select user,length(password) from mysql.user;
+--------------+------------------+
| user         | length(password) |
+--------------+------------------+
| demo         |               41 |
| demo         |               41 |
+--------------+------------------+
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

修改完密碼後,還需要在設定檔中修改下old_passwords選項。把值設定為0。即,
old_passwords=0
然後重啟mysql。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.