php - 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_timeout
不得不max_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/
所以然后我尝试查看一个名为“ Why is /etc/mysql/my.cnf EMPTY? ”的线程,并且用户说要使用以下路径之一:
/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_timeout
和max_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,根据用户@jibe 的链接,php 更改可能已经解决了,如果有人仍然无法解决问题,我让这两个其他链接 链接 1 和链接2 。
更新
对于有问题的用户:一个名为 @Ganesh 的用户也给出了这个解决方案: ALTER USERusername
@localhost
IDENTIFIED WITH caching_sha2_password BY 'password';
或者
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
我希望它有帮助:D
解决方案
在 mysql 配置文件(在 CentOS,etc/my.conf 中)添加以下行:
default_authentication_plugin=mysql_native_password
这成功了。希望能帮助到你。
我的环境:
- CentOS 7
- PHP 7.2
- MySQL 8
推荐阅读
- java - 使用 HtmlUnit 2.35.0 进行网页抓取
- angular - :主机样式未在 angular6 中应用
- java - kafka消费者endOffsets的一致性
- java - 如何修复“字段列表”中的未知列“i”
- azure - 重写 Azure API 管理基本身份验证的问题
- javascript - 如何提取嵌套对象数组中“启用”对象的路径
- css - 免费 wordpress.com 网站上的全角页面
- apache-zookeeper - 使用 zookeeper 设置 clickhouse 3 节点循环集群时,clickhouse 副本/服务器无法相互连接
- java - 具有不同类型的多态列表的对象的序列化
- networking - 如何在ionic4中使用network.onDisconnect