Wednesday, March 29, 2023

Server sent charset unknown to the client.

 After install mysql 8. I'm trying to connect to a MySQL database from php. 


<?php

echo "Hello World!";

?>


</br>

<?php

$link = mysqli_connect('localhost', 'root', 'pass12#####');

if (!$link) {

echo "Failed to connect to MySQL: " . mysqli_connect_error();

die('Could not connect: ' . mysqli_error());

}

echo 'Connected successfully';

mysqli_close($link);

?>


</br>

<?php

phpinfo();

?>

</br>

But when I put in username and password I get the error message saying:


Server sent charset unknown to the client. Please, report to the developers

Solution

MySQL 8 changed the default charset to utf8mb4. But some clients don't know this charset. Hence when the server reports its default charset to the client, and the client doesn't know what the server means, it throws this error.


Edit my.cnf, specify the client code, and add the following content.


[client]

default-character-set=utf8


[mysql]

default-character-set=utf8


[mysqld]

collation-server = utf8_unicode_ci

character-set-server = utf8


No comments:

Post a Comment

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...