大家都知道,从php5.6版本开始就支持mysqli函数了,但同时还是可以使用mysql函数的,但不管使用这其中哪一种函数,似乎都无法连接mysql8版本的数据库,一连接就报错:The server requested authentication method unknown to the client,大家都知道MySQL 8 默认字符集为utf8mb4,解决方法都是设置MySQL的默认字符集为老版本的utf8。
那么如何解决呢:
只要在mysql的配置文件中加上如下几行配置,然后重启mysql就行了:
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
#MySQL8中用户的认证类型(Authentication type)默认为cacheing sha2 password
default_authentication_plugin=mysql_native_password
上面配置好后,将mysql服务重启一下就可以了。
至于mysql配置文件在哪里,我的测试环境是windows10,mysql配置文件为my.ini,它的位置在:C:\ProgramData\MySQL\MySQL Server 8.0;具体位置请按照您实际位置为准,不知道在哪请百度一下。