Mysql issue: Warning: mysqli_real_connect(): Error while reading greeting packet

Posted January 21, 2021 4.5k views

Hi guys, I hope you can help me. I’m launching a web site and I’m having issues with my droplet. I use 5$ droplet to run a wordpress site which uses mysql. At some points (not always) there is an error:

Warning: mysqlirealconnect(): Error while reading greeting packet. PID=862598 in /var/www/html/wp-includes/wp-db.php on line 1653

Here is the line 1653:

mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );

Mysql version:
mysql Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))

I checked the error.log, but I can not find anything meaningful:

Please advise me how to fix the issue

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @jasminap,

There was a similar question regarding the same issue that you are seeing in your logs here:


This crash is most likely due to your system running out of memory. I’d suggest that you add a swap file to give yourself a bit more of a buffer. Check out this tutorial:

How To Add Swap on Ubuntu 18.04

What you can also do is to use the MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

  • SSH to your Droplet
  • Download the script:
wget -O
  • Then execute it:

The script would run multiple checks against your MySQL instance, all checks done by MySQLTuner are documented here.

Also as stated in the official documentation, it is still extremely important for you to fully understand each change you make to a MySQL database server. If you don’t understand portions of the script’s output, or if you don’t understand the recommendations, you should consult a knowledgeable DBA or system administrator that you trust.

As a good practice make sure to always test your changes on staging environments before implementing them on your production database.

On the same note, if you want to have worry-free MySQL hosting and focus on your application, I would recommend trying out the DigitalOcean Managed Databases:



  • Hi @bobbyiliev

    Thank you very much for your answer. I enabled the swap on my server and configured the following:

    Do you think the values are good?

    I also run mysqltuner script and this is the result:

    General recommendations:
    Control warning line(s) into /var/log/mysql/error.log file
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this:
    Variables to adjust:
    *** MySQL's maximum memory usage is dangerously high ***
    *** Add RAM before increasing MySQL buffer variables ***
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size


    • Hi there @jasminap,

      The SWAP settings look good!

      Yes indeed, as far as I can see MySQL Tunner is suggesting that the memory assigned to MySQL is too high compared to the available RAM on the server, this could explain the problems. I could suggest adjusting the MySQL settings so that it uses a reasonable amount of memory compared to the actual available RAM on the server.