I'm trying to connect to a MySQL database from a Symfony 3 application. But when trying to create a MySQL schema from a Symfony console command, I get this error: PDO::__construct(): The server sent a character set (255) unknown to the client. Please report to the developers
Both PHP and MySQL run in Docker containers.
MySQL version: 8.0.1
PHP version: 7.1.3
Driver: pdo_mysql
Character set: UTF8
dsn: "mysql:host=mysql;dbname=database;charset=UTF8;"
Any ideas?
After upgrading to MySQL 8.0.11, I encountered the same problem as the OP when using PHP's
mysqli_connect()
function. In my MySQL directory (in my case,usr/local/mysql
), I created themy.cnf
file, added the content from the accepted answer, and then Restart the MySQL server. However, this produced a new error:mysqli_connect(): The server requests an authentication method unknown to the client [caching_sha2_password]
I added the line
default_authentication_plugin = mysql_native_password
, somy.cnf
now looks like:I'm so excited to go!
More references:https://github.com/laradock/laradock/issues/1392
Please note ARA1307’s comment:
"Please note that you should create new users and explicitly specify "IDENTIFIED WITH mysql_native_password", and change existing users, for example:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
”MySQL 8 changes the default character set to utf8mb4. But some customers don't know this character set. So this error is thrown when the server reports its default character set to the client and the client does not know what the server means.
See alsohttps://bugs.mysql.com/bug.php?id= 71606
This bug is specific to MySQL Connector/C, so it affects more than just PHP.
The correct solution is to upgrade the client, but in the meantime I got it working by changing the server's charset to utf8 to be compatible with non-upgraded clients. I added this to /etc/my.cnf and restarted mysqld:
I found these settings in this 2010 answer: Change MySQL default charset in my.cnf to UTF-8?