我有一个 Laravel 6.2 应用程序,到目前为止它是一个几乎开箱即用的基本应用程序。我使用了 Laravel 开箱即用的身份验证脚手架并创建了一个用户,并且能够在我的数据库(mysql 工作台)中看到该用户。用户已创建,但随后我使用 php artisanserve 命令,然后尝试以我刚刚创建的用户身份登录,浏览器挂起大约 1 分钟,然后抛出以下错误:
Doctrine\DBAL\Driver\PDOException
SQLSTATE[HY000] [2006] MySQL server has gone away
我研究了与此命令相关的其他帖子,并检查了我的 mysql 超时,我增加了限制,但它仍然输出此错误。可能是什么问题?我包括了 mysql 的输出,这样你们都可以看到。
SHOW VARIABLES LIKE '%timeout%';
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 31536000 |
| lock_wait_timeout | 31536000 |
| mysqlx_connect_timeout | 30 |
| mysqlx_idle_worker_thread_timeout | 60 |
| mysqlx_interactive_timeout | 28800 |
| mysqlx_port_open_timeout | 0 |
| mysqlx_read_timeout | 30 |
| mysqlx_wait_timeout | 28800 |
| mysqlx_write_timeout | 60 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 31536000 |
+-----------------------------------+----------+
SHOW STATUS WHERE variable_name = 'Threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 2 |
+-------------------+-------+
SHOW STATUS WHERE variable_name LIKE 'Connections';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Connections | 24 |
+---------------+-------+
Mysql版本
mysql --version
mysql Ver 8.0.18-0ubuntu0.19.10.1 for Linux on x86_64 ((Ubuntu))
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.060 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.058 ms
最佳答案
The php.net manual has an explanation:
When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server’s default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used.
This is because MySQL 8 defaults to caching_sha2_password, a plugin that is not recognized by the older PHP (mysqlnd) releases. Instead, change it by setting default_authentication_plugin=mysql_native_password in my.cnf. The caching_sha2_password plugin will be supported in a future PHP release. In the meantime, the mysql_xdevapi extension does support it.
关于php - Doctrine\DBAL\Driver\PDOException SQLSTATE[HY000] [2006] MySQL 服务器已消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59705543/