mysql 版本 8.0.11 和 Symfony 4 错误“MySQL 服务器已消失”

mysql 版本 8.0.11 和 Symfony 4 错误“MySQL 服务器已消失”

我正在使用 Symfony 4,Mysql 版本是 8.0.11,并且使用用户而不是 root 登录,当我尝试使用该命令时php bin/console make:migration出现此错误:

In AbstractMySQLDriver.php line 126:                                                                                 
An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away                                                                                

In PDOConnection.php line 50:                                           
SQLSTATE[HY000] [2006] MySQL server has gone away  

In PDOConnection.php line 46:                                                
SQLSTATE[HY000] [2006] MySQL server has gone away  

In PDOConnection.php line 46: 
PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109  

然后我尝试在线搜索,发现 MySQL 变量出了问题wait_timeoutmax_allowed_packet必须更改文件中的这些变量/etc/mysql/my.cnf,问题是当我去编辑该文件时我只发现这个:

# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

然后我尝试查看一个名为“为什么 /etc/mysql/my.cnf 是空的?“并且有用户说使用以下其中一条路径:

/etc/mysql/conf.d/
/etc/mysql/mysql.conf.d/
/etc/mysql/mysql.conf.d/mysqld.cnf

所以我尝试了... /etc/mysql/conf.d/

## Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysql]

在文件中/etc/mysql/mysql.conf.d/

# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log

并在文件中/etc/mysql/mysql.conf.d/mysqld.cnf

# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log

并且在任何这些文件中我都找不到 MySQL 变量wait_timeoutmax_allowed_packet,所以如果有人能帮助我解决这个问题,我提前谢谢了。:)

PS:(php bin/console make:migration在出现此错误之前我已经运行过此命令几次,并且创建了数据库,并且运行正常,所以这似乎不是安装问题)。

更新:似乎成功地改变了两个变量wait_timeout,并max_allowed_packet通过在三个文件中添加以下内容来全局改变

max_allowed_packet=1024M 
wait_timeout=3000000

然后使用此命令sudo service mysql restart
给我这个:

mysql> SHOW global VARIABLES LIKE "wait_timeout";
+---------------+---------+
| Variable_name | Value   |
+---------------+---------+
| wait_timeout  | 3000000 |
+---------------+---------+
1 row in set (0,00 sec)

mysql> SHOW VARIABLES like 'max_allowed_packet';
+--------------------+------------+
| Variable_name      | Value      |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+
1 row in set (0,00 sec)

但是当我尝试使用此命令时,php bin/console make:migration它仍然给了我这篇文章上面提到的相同错误,也尝试用wait_timeout相同的方法将变量更改为 300,它给了我相同的结果。:(

使用此命令sudo vim /var/log/mysql/error.log我得到这个:

2018-07-29T18:55:18.382164Z 0 [Warning] [MY-010909] [Server] /usr/sbin/mysqld: Forcing close of thread 8  user: 'alexandre'.
2018-07-29T18:55:20.288756Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.
2018-07-29T18:55:20.642118Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 31833
2018-07-29T18:55:21.704556Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-07-29T18:55:21.720385Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

更新: 我已经卸载了 mysql 和 php,并改为 mysql 5.7 和 php 7.2.7,php 的更改可能会解决这个问题关联 用户@jibe,如果有人仍然无法解决问题,我会让这两个其他链接 链接1链接2

答案1

我知道这已经过去很久了,但我找到了答案。使用以下命令使用新的身份验证插件更新您的密码。您现在可以使用 MySQL 8。玩得开心。

ALTER USER `username`@`localhost` IDENTIFIED WITH caching_sha2_password BY 'password';

或者

ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

相关内容