解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

今天想登陆下mysql查询一下数据,结果发现客户端连接不上,报错提示:2003-Can't connect to MySQL server on local(10061 "Unkown error"),然后进入到linux 里的mysql,一样连接不上, 报错提示:解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'。 

然后也在网上查询了一些方法:这里给各位汇总一下(少,请莫见怪)

https://www.cnblogs.com/adolfmc/p/5875584.html

https://www.cnblogs.com/wzg123/p/6723338.html

https://www.cnblogs.com/panxuejun/p/6151407.html

https://blog.csdn.net/xiaoshunzi111/article/details/52797913

https://blog.csdn.net/qq_34369025/article/details/77351709

https://blog.csdn.net/sanqima/article/details/50506274

https://stackoverflow.com/questions/119008/cant-connect-to-mysql-server-on-localhost-10061

然鹅,这些都不适合我,我注意到其中有个说,报这样的错“Can't connect to local MySQL server through socket”,意味着socket这个文件不存在,但是我的目录下是的确存在的(日期是5月31号)

解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'_第1张图片

所以我索性把这个文件删掉, 再重新建一个相同名字的文件。

解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'_第2张图片

修改时间是今天拉,也就是7月20号。然后输入命令,尝试登陆本机mysql: (发现已经没有再报错了)

$ ./bin/mysql --socket=~/local/mysql/mysql_3308.sock -uroot password *****

./bin/mysql  Ver 14.14 Distrib 5.6.40, for Linux (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: ./bin/mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)

现在开启mysql服务:

$ nohup ./bin/mysqld_safe --defaults-file=~/local/mysql/my.cnf &
[1] 10449
nohup: 忽略输入并把输出追加到"nohup.out"
$ ps
  PID TTY          TIME CMD
10449 pts/13   00:00:00 mysqld_safe
10630 pts/13   00:00:00 mysqld
10909 pts/13   00:00:00 ps
32009 pts/13   00:00:00 bash
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.40-log Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

再登陆就没有问题了。

你可能感兴趣的:(数据库)