SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers

10,012

Solution 1

What version of PHP are you using?

According to PHP's bugtracker, this should be fixed as of 7.0.19, 7.1.5, and 7.2.0.

https://bugs.php.net/bug.php?id=74461

Some answers recommended changing the server charset back to utf8 from utf8mb4, but that is a bad idea. utf8 doesn't support the full range of valid unicode characters, so trying to save a string that contains certain characters (like some sets of emoji) will cause a database error. It is much better to simply upgrade PHP to a more recent version.

Solution 2

make sure you create a database first. then, Make sure that you have correct params when it comes to the database in your .env file. Here scenario for localhost:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306 (this can be different when database changed.)
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_pass

also run : php artisan config:cache to clear cache.

it work for me.. good luck

Solution 3

<?php

$servername = "localhost";

$username = "root";

$password = "";



try{

    // servername and database name
    // my port no is 3307 check your's
    $conn = new PDO('mysql:host = $servername; dbname=project1; ', $username, $password );


    // set the PDO error mode
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected Successfully";

}
catch(PDOException $e){

    
    echo "Your Connection failed: ".$e->getMessage();
}


?>
Share:
10,012

Related videos on Youtube

ALBADI
Author by

ALBADI

Updated on June 04, 2022

Comments

  • ALBADI
    ALBADI almost 2 years

    I am trying to create a login system in laravel. I've updated env. file with a database called kokodb. However, when I run this code 'php artisan migrate' in cmd, I came up with the following error:

    In Connection.php line 647:

    SQLSTATE[HY000] [2054] Server sent charset unknown to t he client. Please, report to the developers (SQL: selec t * from information_schema.tables where table_schema = kokodb and table_name = migrations)

    In Connector.php line 68:

    SQLSTATE[HY000] [2054] Server sent charset unknown to t he client. Please, report to the developers

    In Connector.php line 68:

    PDO::__construct(): Server sent charset (255) unknown t o the client. Please, report to the developers

    Can you please help me. I did not find any solution to this problem anywhere else.

    • Travis Britz
      Travis Britz over 5 years
      What version of PHP and Laravel is this?
    • ALBADI
      ALBADI over 5 years
      it was version 5. and now it is it is 7.2.11. but this does not solve the problem
    • Travis Britz
      Travis Britz over 5 years
      To clarify, it was PHP 5 and then you installed PHP 7.2.11? If so, have you verified that both your webserver and your command line are now using the new php version?
    • Adam Kozlowski
      Adam Kozlowski over 5 years
      did you find solotion?
    • ALBADI
      ALBADI over 5 years
      It seems that upgrading PHP has solved the charset problem. however, now I am facing another problem when I am trying to migrate. SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = kokodb andtable_name = migrations).
  • Travis Britz
    Travis Britz over 5 years
    I wouldn't recommend config:cache during development
  • Adam Kozlowski
    Adam Kozlowski over 5 years
    Hey man, you wouldn't recommend config:cache during development? Maybe you will give us a reason?
  • Travis Britz
    Travis Britz over 5 years
    Of course, sorry. If you are already caching config then yes, you need to run config:cache again (and during deployment). For dev, when config options change often, it's easy to forget that step (and the benefits of optimizing your local machine are small). It can lead to hours of "why won't my change work?" kinds of debugging (the first time). On Stackoverflow I expect there to be a lot of inexperienced Laravel devs who wouldn't remember that they'd run config:cache a week ago when they were running commands from suggested fixes. One less pothole for them to step in.
  • Syscall
    Syscall about 3 years
    Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.