Skip to content

Instantly share code, notes, and snippets.

@adrianorsouza
Last active January 12, 2020 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianorsouza/5133389dc1c23446cb26a49ef7a98fe4 to your computer and use it in GitHub Desktop.
Save adrianorsouza/5133389dc1c23446cb26a49ef7a98fe4 to your computer and use it in GitHub Desktop.
Fix PHP 7.4 + MySQL 8 errors with server has gone away

Fix PHP 7.4 + MySQL 8 errors with server has gone away

PHP 7.4 is now released, and it comes with support for MySQL 8's new password authentication plugin: caching_sha2_password.

1. Connect to the database as root

Depending on your root username, you will be prompted to enter the password, a hostname, etc. By default, typing mysql in your server terminal should work. If you have trouble logging in, try mysql -p -u root, and entering the root password when asked.

2. Check existing authentication plugin:

Replace USERNAME and YOUR_PASSWORD with your application database username and the password.

mysql> SELECT user,plugin from mysql.user;

Sample output

+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| Ayesh            | caching_sha2_password |
| debian-sys-maint | mysql_native_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session    | mysql_native_password |
| mysql.sys        | caching_sha2_password |
| root             | auth_socket           |
| testuser         | mysql_native_password |
+------------------+-----------------------+

If you see mysql_native_password next to the database user's name, you can now change it to caching_sha2_password.

3. Change MySQL authentication plugin to caching_sha2_password

mysql> ALTER USER 'USERNAME'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'YOUR_PASSWORD';
mysql> FLUSH PRIVILEGES;

https://php.watch/articles/PHP-7.4-MySQL-8-server-gone-away-fix https://laravel-news.com/laravel-and-mysql-8-fixing-mysql-server-has-gone-away-error

https://stackoverflow.com/questions/50026939/php-mysqli-connect-authentication-method-unknown-to-the-client-caching-sha2-pa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment