问题
I have just installed php7.4, everything seems ok but when I try to go on my phpmyadmin, I can't : Note works fine in php7.3 before this installation
The error is :
mysqli_real_connect(): Unexpected server response while doing caching_sha2 auth: 109
mysqli_real_connect(): (HY000/2006): MySQL server has gone away
looking my php mysql library :php7.4-mysql
. it's installed.
Forget something ? Thank you.
NOTICE: Not enabling PHP 7.4 FPM by default.
NOTICE: To enable PHP 7.4 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php7.4-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Traitement des actions différées (« triggers ») pour libapache2-mod-php7.4 (7.4.
0-1+ubuntu19.10.1+deb.sury.org+1) ...
apt-cache policy php7.4
php7.4:
Installé : 7.4.0-1+ubuntu19.10.1+deb.sury.org+1
Candidat : 7.4.0-1+ubuntu19.10.1+deb.sury.org+1
Table de version :
*** 7.4.0-1+ubuntu19.10.1+deb.sury.org+1 500
500 http://ppa.launchpad.net/ondrej/php/ubuntu eoan/main amd64 Packages
500 http://ppa.launchpad.net/ondrej/php/ubuntu eoan/main i386 Packages
100 /var/lib/dpkg/status
回答1:
If you still use the dated mysql_native_password
method, which is HIGHLY DISCOURAGED as it is considered less secure, you could set the default authentication plug-in to native password by adding default_authentication_plugin = mysql_native_password
to the [mysqld]
section of my.cnf.
回答2:
I had the same issue, but using mysql_native_password
was not possible with PHP7.4-mysql-pdo
, even on setting in my.cnf
as it worked on PHP7.3-mysql-pdo
.
I had to alter every user with this query:
ALTER USER 'username'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
where username
is the database username and password
is the password of the database user.
回答3:
In file /etc/mysql/my.cnf
After [mysqld]
add:
default-authentication-plugin = mysql_native_password
Example of my /etc/mysql/my.cnf
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
log-error = /var/log/mysql/error.log
explicit_defaults_for_timestamp
bind-address = 0.0.0.0
# PHP 7.4 Fix
default-authentication-plugin = mysql_native_password
# Recommended in standard MySQL setup
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
And remember use mysql_native_password not good because of security.
回答4:
you can change the encryption of the password like this.
ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
来源:https://stackoverflow.com/questions/59120368/php7-4-mysqli-times-out-with-gone-away