简体   繁体   English

无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器(错误2002)

[英]Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (error 2002)

I know this is a question many times asked, but I can't seem to find any solution out of the other topics. 我知道这是一个经常被问到的问题,但是我似乎无法从其他主题中找到任何解决方案。

what I've tried: 我尝试过的

  • reinstalling mysql-server (so not the client) 重新安装mysql服务器(不是客户端)
  • chown mysql:mysql /var/lib/mysql
  • checked out my.cnf where everything seems correct 签出my.cnf似乎一切正确的地方
  • changed bind-address to localhost 将bind-address更改为localhost
  • at a certain point it seemed I had no socket file and 在某些时候,似乎我没有套接字文件,

    sudo find / -type s | grep mysqld.sock sudo find / -type s | grep mysqld.sock doesn't give any result. sudo find / -type s | grep mysqld.sock没有给出任何结果。


Edit 编辑

I now entered mysql_config --socket and it seems there is a socket file in place now at /var/run/mysqld/mysqld.sock 我现在输入mysql_config --socket ,似乎现在在/var/run/mysqld/mysqld.sock处有一个套接字文件。

also checked apparmor_status which gave following result: 还检查了apparmor_status ,结果如下:

apparmor module is loaded.
14 profiles are loaded.
14 profiles are in enforce mode.
   /sbin/dhclient
   /usr/bin/evince
   /usr/bin/evince-previewer
   /usr/bin/evince-previewer//sanitized_helper
   /usr/bin/evince-thumbnailer
   /usr/bin/evince-thumbnailer//sanitized_helper
   /usr/bin/evince//sanitized_helper
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/connman/scripts/dhclient-script
   /usr/lib/cups/backend/cups-pdf
   /usr/sbin/cups-browsed
   /usr/sbin/cupsd
   /usr/sbin/mysqld
   /usr/sbin/tcpdump
0 profiles are in complain mode.
3 processes have profiles defined.
0 processes are in enforce mode.
0 processes are in complain mode.
3 processes are unconfined but have a profile defined.
   /sbin/dhclient (1089) 
   /usr/sbin/cups-browsed (1415) 
   /usr/sbin/cupsd (16608) 

After all this /etc/init.d/mysql start still fails 在所有这些/etc/init.d/mysql start仍然失败

settings in my.cnf my.cnf中的设置

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

I checked out /var/log/error.log and when I try # /etc/init.d/mysql start following reports show up from the log: 我签出了/var/log/error.log ,当我尝试# /etc/init.d/mysql start ,从日志中显示以下报告:

150528 22:58:19 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150528 22:58:19 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150528 22:58:19 [Note] /usr/sbin/mysqld (mysqld 5.5.43-0ubuntu0.14.04.1) starting as process 14608 ...
150528 22:58:19 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150528 22:58:19 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150528 22:58:19 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
150528 22:58:19 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
150528 22:58:19 InnoDB: The InnoDB memory heap is disabled
150528 22:58:19 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150528 22:58:19 InnoDB: Compressed tables use zlib 1.2.8
150528 22:58:19 InnoDB: Using Linux native AIO
150528 22:58:19 InnoDB: Initializing buffer pool, size = 128.0M
150528 22:58:19 InnoDB: Completed initialization of buffer pool
150528 22:58:19 InnoDB: highest supported file format is Barracuda.
150528 22:58:19  InnoDB: Waiting for the background threads to start
150528 22:58:20 InnoDB: 5.5.43 started; log sequence number 140421610
150528 22:58:20 [Note] Server hostname (bind-address): 'localhost'; port: 3306
150528 22:58:20 [Note]   - 'localhost' resolves to '127.0.0.1';
150528 22:58:20 [Note] Server socket created on IP: '127.0.0.1'.
150528 22:58:20 [ERROR] /usr/sbin/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
150528 22:58:20 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
150528 22:58:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

Can someone help me out how to get it fixed without loosing my db's 有人能帮我解决问题而又不丢失数据库的问题吗

Your mysql install is hosed: 您的mysql安装已完成:

150528 22:58:20 [ERROR] /usr/sbin/mysqld: Can't find file: './mysql/host.frm' (errno: 13)

It's not starting up in the first place, hence not having a socket file. 它不是一开始就没有启动,因此没有套接字文件。 You're missing data from the internal/core mysql database, which is a very bad sign. 您从内部/核心mysql数据库中丢失了数据,这是一个非常糟糕的信号。

If you haven't initialized the data directory, now is the time to initialize it before starting mysqld . 如果尚未初始化数据目录,现在是在启动mysqld之前对其进行初始化的时候了。

You can run either of these 2 scripts provided by mysql. 您可以运行mysql提供的这两个脚本之一。 From your shell prompt run them as: 在您的shell提示符下,将它们运行为:

# mysql_secure_installation

or 要么

# mysql_install_db --user=mysql \
         --basedir=<path to mysql install dir> \
         --datadir=/var/lib/mysql/data

mysql_install_db will invoke mysqld with --bootstrap and --skip-grant-tables options. mysql_install_db将使用--bootstrap--skip-grant-tables选项调用mysqld

The mysql_install_db cmd did the trick. mysql_install_db cmd可以解决问题。 I have a socket again and I"m now able to login to mysql again. Thx 我又有了一个套接字,现在可以再次登录mysql了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OperationalError: (2002, &quot;Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2)&quot;) - OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") (2002,“无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2)”) - (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") mysql ERROR 2002 (HY000): 无法通过 socket &#39;/var/run/mysqld/mysqld.sock&#39; 连接到本地 MySQL 服务器 (2) - mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 错误2002(HY000):无法通过Vagrant中的套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in Vagrant ERROR 2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(111) - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 错误 2002 (HY000):无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 错误 2002 (HY000): 无法通过套接字'/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 错误2002(HY000):无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) occured mysql错误“无法通过套接字&#39;/var/run/mysqld/mysqld.sock连接到本地MySQL服务器” - mysql error “Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock” 出现错误:无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器(2) - Getting error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM