1. 程式人生 > >PHP:使用mysqli連線mysql

PHP:使用mysqli連線mysql

提示:

     使用 PHP 7.1.16 之前的版本或者 PHP 7.2(PHP 7.2.4 之前的版本), 需要將 MySQL 伺服器的預設密碼外掛設定為:mysql_native_password。 否則,當你連線的時候就會看到類似這樣的錯誤: The server requested authentication method unknown to the client [caching_sha2_password]。 即使你未使用 caching_sha2_password 也會這樣。

發生這種錯誤的原因是,MySQL 8 伺服器預設會使用 caching_sha2_password 擴充套件, 老版本的 PHP 驅動(mysqlnd)無法識別這個擴充套件。

例如,在mysql中操作:

use mysql;

alter user 'php'@'%' identified with mysql_native_password by '[email protected]';