需求

要使用 mysqli 相關(guān)的函數(shù), 你必須以啟用 mysqli 擴(kuò)展的方式編譯 PHP。

MySQL 8

使用 PHP 7.1.16 之前的版本或者 PHP 7.2(PHP 7.2.4 之前的版本), 需要將 MySQL 服務(wù)器的默認(rèn)密碼插件設(shè)置為:mysql_native_password。 否則,當(dāng)你連接的時(shí)候就會(huì)看到類似這樣的錯(cuò)誤: The server requested authentication method unknown to the client [caching_sha2_password]。 即使你未使用 caching_sha2_password 也會(huì)這樣。

發(fā)生這種錯(cuò)誤的原因是,MySQL 8 服務(wù)器默認(rèn)會(huì)使用 caching_sha2_password 擴(kuò)展, 老版本的 PHP 驅(qū)動(dòng)(mysqlnd)無法識(shí)別這個(gè)擴(kuò)展。 所以需要在 MySQL 的配置文件 my.cnf 中,設(shè)置 default_authentication_plugin=mysql_native_password。 在后續(xù)的 PHP 發(fā)行版本中,會(huì)提供對(duì) MySQL caching_sha2_password 擴(kuò)展的支持。 目前只有 mysql_xdevapi 擴(kuò)展是 支持 MySQL 的 caching_sha2_password 擴(kuò)展的。