MySQL ERROR 2002(HY000):无法通过套接字连接到本地MySQL服务器

时间:2017-02-14 17:03:32

标签: php mysql bitnami

当我的Wordpress服务器开始抛出MySQL错误时,我注意到了这个问题。为了尝试调试Wordpress,我尝试手动连接。

我得到以下内容:

$ mysql -u root -p -h localhost -P 3306                                                                                                                                         
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/bitnami/mysql/tmp/mysql.sock' (2)

我也尝试过没有-h选项和127.0.0.1

看起来MySQL正在运行。

$ ps -ef | grep mysql                                                                                                                                                           
mysql    14743     1  0 15:20 ?        00:00:00 /usr/sbin/mysqld
bitnami  14939 13882  0 15:28 pts/0    00:00:00 grep --color=auto

安装了mysql-server,但/opt/bitnami/mysql/tmp/mysql.sock不存在。

看起来MySQL正在侦听正确的端口。

$ telnet 127.0.0.1 3306
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
[
5.5.54-0ubuntu0.14.04.1,IIq{;Rh�k>5/)"m"[&J#mysql_native_password

!#08S01Got packets out of orderConnection closed by foreign host.

Following the suggestion here:

$ sudo /opt/bitnami/ctlscript.sh status
php-fpm already running
apache already running
mysql not running
$ sudo /opt/bitnami/ctlscript.sh start mysql
2017-02-14T16:53:25.064586Z mysqld_safe Logging to '/opt/bitnami/mysql/data/mysqld.log'.
2017-02-14T16:53:25.233250Z mysqld_safe Starting mysqld.bin daemon with databases from /opt/bitnami/mysql/data
2017-02-14T16:53:28.400598Z mysqld_safe mysqld from pid file /opt/bitnami/mysql/data/mysqld.pid ended
/opt/bitnami/mysql/scripts/ctl.sh : mysql  could not be started
Monitored mysql

以下是/opt/bitnami/mysql/data/mysqld.log中的一些选择行。它看起来像是冲突。

2017-02-14T17:03:31.274720Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2017-02-14T17:03:31.274778Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2017-02-14T17:03:31.274835Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2017-02-14T17:03:31.274888Z 0 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
2017-02-14T17:03:31.274901Z 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?
2017-02-14T17:03:31.274952Z 0 [ERROR] Aborting

2 个答案:

答案 0 :(得分:1)

问题是你已经运行了一个不是bitnami的mysql服务器。您应该在从bitnami启动mysql服务器之前先停止该服务。

您可以尝试停止:

$ sudo service mysql stop

如果它不起作用,你可以终止这个过程:

$ sudo kill 14743

最后用这个命令启动bitnami mysql服务器:

$ sudo /opt/bitnami/ctlscript.sh start mysql

此服务器运行后,您应该可以毫无问题地连接。

答案 1 :(得分:0)

在做任何事情之前先检查空间。确保它没有被 100% 使用

df -h

enter image description here

如果有可用空间。

用于检查 Mysql 是否正在运行。

ps xufa | grep mysql

重启mysql

sudo service bitnami restart mysql