Ale*_*ira 5 php mysql symfony4
我正在使用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
Run Code Online (Sandbox Code Playgroud)
然后我试着在网上搜索,我发现,出事了与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/
Run Code Online (Sandbox Code Playgroud)
所以我试图看到一个名为" 为什么是/etc/mysql/my.cnf EMPTY? " 的线程,并且用户说要使用以下路径之一:
/etc/mysql/conf.d/
/etc/mysql/mysql.conf.d/
/etc/mysql/mysql.conf.d/mysqld.cnf
Run Code Online (Sandbox Code Playgroud)
所以我试过......
/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]
Run Code Online (Sandbox Code Playgroud)
在文件中/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
Run Code Online (Sandbox Code Playgroud)
并在文件中/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
Run Code Online (Sandbox Code Playgroud)
在这些文件,我没能找到MySQL的变量wait_timeout和max_allowed_packet,所以先感谢如果有人可以帮助我解决这个问题.:)
PS :(我已经php bin/console make:migration在此错误之前多次运行此命令,并且还创建了数据库并且运行正常,因此它似乎不是安装问题).
更新:它似乎成功地更改了两个变量wait_timeout并max_allowed_packet通过向以下三个文件添加全局
max_allowed_packet=1024M
wait_timeout=3000000
Run Code Online (Sandbox Code Playgroud)
然后使用此命令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)
Run Code Online (Sandbox Code Playgroud)
但仍然当我尝试使用此命令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.
Run Code Online (Sandbox Code Playgroud)
更新: 我已经取消了mysql和php并更改为mysql 5.7和php 7.2.7,php更改可能已解决了根据用户@jibe的链接,如果有人仍然无法解决问题我让这两个其他链接 链接1 和link2.
更新
对于有问题的用户:名为@Ganesh的用户也提供了此解决方案:ALTER USERusername@localhostIDENTIFIED WITH caching_sha2_password BY'password';
要么
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助:D
在 mysql 配置文件(在 CentOS 中,etc/my.conf)中添加以下行:
default_authentication_plugin=mysql_native_password
Run Code Online (Sandbox Code Playgroud)
这成功了。希望能帮助到你。
我的环境: