Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
580 views
in Technique[技术] by (71.8m points)

mysql - 错误:“无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器” —缺少/var/run/mysqld/mysqld.sock(error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' — Missing /var/run/mysqld/mysqld.sock)

My problem started off with me not being able to log in as root any more on my mysql install.

(我的问题开始于我无法以root用户身份登录mysql安装。)

I was attempting to run mysql without passwords turned on... but whenever I ran the command

(我试图在不打开密码的情况下运行mysql ...但是每当我运行命令时)

# mysqld_safe --skip-grant-tables &

I would never get the prompt back.

(我永远也回不了提示。)

I was trying to follow these instructions to recover the password .

(我试图按照以下说明恢复密码 。)

The screen just looks like this:

(屏幕如下所示:)

root@jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables
120816 11:40:53 mysqld_safe Logging to syslog.
120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

and I don't get a prompt to start typing the SQL commands to reset the password.

(并且没有提示您开始输入SQL命令来重置密码。)

When I kill it by pressing CTRL + C , I get the following message:

(当我按CTRL + C杀死它时,我收到以下消息:)

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

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

If I retry the command and leave it long enough, I do get the following series of messages:

(如果重试该命令并将其保留足够长的时间,则会收到以下一系列消息:)

root@jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog.
120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    mysqld_safe --skip-grant-tables
root@jj-SFF-PC:/run/mysqld#

But then if I try to log in as root by doing:

(但是,如果我尝试通过以下方式以root用户身份登录:)

# mysql -u root

I get the following error message:

(我收到以下错误消息:)

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

I checked and /var/run/mysqld/mysqld.sock file doesn't not exist.

(我检查了/var/run/mysqld/mysqld.sock文件不存在。)

The folder does, but not the file.

(文件夹可以,但文件不能。)

Also, I dunno if this helps or not, but I ran find / -name mysqld and it came up with:

(另外,我不知道这是否有帮助,但是我find / -name mysqld ,结果是:)

/var/run/mysqld - folder
/usr/sbin/mysqld - file
/run/mysqld - folder

I'm new to Linux and MySQL, so I don't know if this is normal or not.

(我是Linux和MySQL的新手,所以我不知道这是否正常。)

But I'm including this info just in case it helps.

(但我会包含此信息,以防万一。)

I finally decided to uninstall and reinstall mysql.

(我终于决定卸载并重新安装mysql。)

apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-common
apt-get remove phpmyadmin

After reinstalling all packages again in the same order as above, during the phpmyadmin install, I got the same error:

(按照上述相同的顺序重新安装所有软件包后,在phpmyadmin安装过程中,出现了相同的错误:)

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

So I tried again to uninstall/reinstall.

(所以我再次尝试卸载/重新安装。)

This time, after I uninstalled the packages, I also manually renamed all mysql files and directories to mysql.bad in their respective locations.

(这次,在卸载软件包之后,我还手动将所有mysql文件和目录在各自的位置重命名为mysql.bad 。)

/var/lib/mysql 
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/etc/mysql

Then I tried to reinstall mysql-server and mysql-client again.

(然后,我尝试再次重新安装mysql-servermysql-client 。)

But I've noticed that it doesn't prompt me for a password.

(但是我注意到它不会提示我输入密码。)

Isn't it supposed to ask for an admin password?

(它不是应该要求管理员密码吗?)

  ask by dot translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

试试这个命令

sudo service mysql start

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...