无法在Ubuntu 12.04.5 LTS中通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器 [英] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in Ubuntu 12.04.5 LTS

查看:130
本文介绍了无法在Ubuntu 12.04.5 LTS中通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误,无法在Ubuntu 12.04.5 LTS中通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器. 因此,我从Ubuntu 12.04.5 LTS 卸载了mysql 5.5 .但是当我尝试安装mysql 时,我无法安装mysql.

I encountered with the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in Ubuntu 12.04.5 LTS. So,I uninstalled mysql 5.5 from Ubuntu 12.04.5 LTS.But when i tried to install mysql,i was unable to install mysql.

我使用以下命令来卸载mysql:

i used the following commands to uninstall mysql:

 sudo apt-get remove --purge mysql-server mysql-client mysql-common
 sudo apt-get remove --purge mysql-server-5.5 mysql-client-5.5 mysql-servercore-5.5 mysql-client-core-5.5
 sudo apt-get autoremove
 sudo apt-get autoclean
 sudo rm -rf /var/lib/mysql
 sudo rm -rf /etc/mysql
 sudo deluser mysql

我使用以下命令来安装mysql 5.5:

I used the following commands to install mysql 5.5:

sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-server

但是遇到以下错误:

 AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in      /etc/apparmor.d/usr.sbin.mysqld at line 9: Could not open 'abstractions/mysql'
 start: Job failed to start
 invoke-rc.d: initscript mysql, action "start" failed.
 dpkg: error processing mysql-server-5.5 (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.
dpkg: error processing mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup    error from a previous failure.
                                                                                                         Errors were encountered while processing:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

当我从终端键入'mysql'时,它返回错误:

When i type 'mysql' from terminal it returns the error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我在谷歌搜索后尝试了 telnet 127.0.0.1 3306 ,它返回了连接被拒绝.

I tried telnet 127.0.0.1 3306 after googling,it returned connection refused.

有人可以提出解决方案吗?

推荐答案

Mariadb对我来说是固定的

Here is what fixed for me with Mariadb

首先找出最可能位于/etc/mysql/my.cnf/etc/my.cnf的mysql配置文件是否具有正确的mysql.sock条目

First find out if your mysql config file ,most likely located at /etc/mysql/my.cnf or /etc/my.cnf has the correct mysql.sock entry or not

您可以通过运行找出mysql.sock文件的位置 find / -type s,如果该条目在您的mysql配置中不正确,请对其进行文件修复,并确保mysql.pid也具有正确的路径.

You can find out where mysql.sock file is located by running find / -type s , if the entry is not correct in your mysql config, file fix it , also make sure mysql.pid has the correct path as well.

现在尝试启动mysql服务器,如果启动正常,并且您可以看到其中的所有数据库和表,那么您就很好了,不需要遵循本文的其余部分.

Now try to start mysql server , if it starts fine and you can see all DB's and tables within , you are good and dont need to follow rest of the post .

如果在修复mysql.sock路径后mysql无法启动,请继续阅读

If mysql fails to start after fixing mysql.sock path , read on

将以下内容添加到您的my.cnf文件中,

Add the following to your my.cnf file ,

innodb_force_recovery = 1,然后重新启动mysql.

innodb_force_recovery = 1 inside the mysqld block , and restart mysql.

如果启动失败,则每次将数字递增1,但请记住,在3​​之后,它们可能会丢失一些数据(这对我而言没有发生,但我仅了解到高于3的任何内容是一种补救措施. ,而不是恢复)

If it fails to start , increment the number by one each time , but keep in mind , after 3 , their might be some data loss (not happened to me , but i have only read about anything above 3 being a salvaging measure , than a recovery)

如果您以前有一些表,不要惊慌,请停止显示它们在引擎中不存在. mysql成功启动(如果您还没有备份,最好立即进行备份,以防万一,从这里开始往南走),从my.cnf文件中删除innodb_force_recovery = 1并再次重新启动mysql,所有表都应该再次可用

Dont panic if some of the tables you previously had , stop showing that they dont exist in the engine . Ones mysql starts successfully (if you dont have a backup yet , better make one now , just in case things go south from here on) , remove innodb_force_recovery = 1 from my.cnf file and restart mysql again , all your tables should be available again.

对我有帮助的帖子

  • https://stackoverflow.com/a/20617180/3117013
  • https://stackoverflow.com/a/11990813/3117013

这篇关于无法在Ubuntu 12.04.5 LTS中通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆