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

时间:2015-05-28 22:00:54

标签: mysql sockets mysql-error-2002

我知道这是一个多次提出的问题,但我似乎无法找到其他主题的任何解决方案。

我尝试了什么:

  • 重新安装mysql-server(所以不是客户端)
  • chown mysql:mysql /var/lib/mysql
  • 查看my.cnf,其中一切似乎都正确
  • 将bind-address更改为localhost
  • 在某一点似乎我没有套接字文件和

    sudo find / -type s | grep mysqld.sock没有给出任何结果。

修改

我现在输入了mysql_config --socket,似乎现在有一个套接字文件/var/run/mysqld/mysqld.sock

还检查了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) 

毕竟这/etc/init.d/mysql start仍然失败

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

我检查了/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

有人可以帮我解决如何在不丢失数据库的情况下修复它的问题

3 个答案:

答案 0 :(得分:0)

你的mysql安装已被软管:

root->right->right

它首先没有启动,因此没有套接字文件。您从内部/核心#include <stdio.h> #include <limits.h> struct tree_node { int key; struct tree_node *left; struct tree_node *right; }; static int is_bst_aux(struct tree_node *root, int min, int max) { if (root == NULL) { return 1; } if (!(min < root->key && root->key < max)) { return 0; } if (!is_bst_aux(root->left, min, root->key)) { return 0; } return is_bst_aux(root->right, root->key, max); } int is_bst(struct tree_node *root) { return is_bst_aux(root, INT_MIN, INT_MAX); } 数据库中丢失了数据,这是一个非常糟糕的信号。

答案 1 :(得分:0)

如果您尚未初始化数据目录,现在可以在开始mysqld之前初始化它。

您可以运行mysql提供的这两个脚本中的任何一个。在shell提示符下运行它们:

# mysql_secure_installation

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

mysql_install_db将使用mysqld--bootstrap选项调用--skip-grant-tables

答案 2 :(得分:0)

Context.ConnectionId cmd就行了。我再次有一个套接字,我现在能够再次登录到mysql.Thx