strace 解决 mysql 连接数据库总是定位/tmp/mysql.sock的问题

查看mysqld和mysql默认读取my.cnf的顺序

···
mysql --help --verbose | grep ‘my.cnf‘
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

mysqld --verbose --help | grep ‘my.cnf‘
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default
···

报错的表现

···
mysql
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
···

stace mysql 命令的执行过程

···
strace /usr/local/mysql/bin/mysql
execve("/usr/local/mysql/bin/mysql", ["/usr/local/mysql/bin/mysql"], [/ 21 vars /]) = 0
= 0
stat("/etc/my.cnf", 0x7ffca8678640) = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", 0x7ffca8678640) = -1 ENOENT (No such file or directory)
stat("/usr/local/mysql/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=3816, ...}) = 0
open("/usr/local/mysql/etc/my.cnf", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3816, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb9595ef000
read(3, "# For advice on how to change se"..., 4096) = 3816
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fb9595ef000, 4096) = 0
stat("/root/.my.cnf", 0x7ffca8678640) = -1 ENOENT (No such file or directory)
stat("/root/.mylogin.cnf", {st_mode=S_IFREG|0600, st_size=504, ...}) = 0
open("/root/.mylogin.cnf", O_RDONLY) = 3
···

删除.mylogin.cnf文件

···
rm /root/.mylogin.cnf
rm: remove regular file ‘/root/.mylogin.cnf’? y
···

再次登录正常

···
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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.
···

原文地址:https://blog.51cto.com/395469372/2419645

时间: 2024-10-08 04:09:55

strace 解决 mysql 连接数据库总是定位/tmp/mysql.sock的问题的相关文章

启动mysql时显示:/tmp/mysql.sock 不存在的解决方法

Can't connect to local MySQL server through socket '/tmp/mysql.sock' 上述提示可能在启动mysql时遇到,即在/tmp/mysql.sock位置找不到所需要的mysql.sock文件,主要是由于my.cnf文件里对mysql.sock的位置设定导致. mysql.sock默认的是在/var/lib/mysql, 如果发现确实是在该目录下,可以在[mysqld]下面加入mysql.sock的pathvi /etc/my.cnf(m

mac 安装mysql 报错“ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)” 解决办法

首先安装 homebrew 再 brew install mysql 之后连接 mysql 无论是登录还是修改初始密码都会报如下的错误 ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2) 运行如下解决:参考 http://www.thinksaas.cn/group/topic/347978/ unset TMPDIR mysql_install_db --v

Mac mySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决办法

我的环境:Mac 10.11.6 ,mysql  5.7.14  . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 这个错是链接时报的错,要链接必须启动.修复的时候首先要启动mysql. 首先来了解一下 mysql.sock的作用: Mysql有两种连接方式: (1),TCP/IP (2),socket 对mysql.sock来说,其

解决连接mysql时报错"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"

命令行连接mysql时,报了“Can't connect to local MySQL server through socket '/tmp/mysql.sock'”的错误:用Navicat连接是报62号错误. 首先确定我本机是装了mysql的 尝试用安全模式启动mysql,命令行执行: /usr/local/bin/mysqld_safe 完了之后运行mysql,成功了. 解决连接mysql时报错"Can't connect to local MySQL server through soc

Mac端解决:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

安装mysql但是从来没启动过,今天一启动就报错: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 其实是mysql服务没起来... localhost:~ miaoying$ mysql.server start Starting MySQL ... SUCCESS! 然后再去sudo mysql就行了 Mac端解决:Can't connect to local MySQL server thro

解决MySQL server through socket ‘/tmp/mysql.sock‘

:/alidata/www/default# mysql -u root -h localhost -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 可能的解决方案(未试过) 看my.cnf的sock file path --socket or -S 看my.cnf配置的路径,如果修改了 两种方案 mysql每次都带上soc

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

我在源码编译安装mysql后,虽然mysql服务可以正常启动,但是当我直接执行mysql后,出现了错误. 错误提示如下: [[email protected] ~]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 出现错误原因: 由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总

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

原因:找不到mysql.sock文件 解决方法: 1 找到mysql.sock文件位置 echo "show variables" | mysql | grep "socket"或者echo "status" | mysql | grep "socket" 2 ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock 将两个文件做一个软连接 ERROR 2002 (HY000): C

Mac OS X下MySQL出现Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的问题

网上类似的很多,大都是说修改my.cnf之类的,在我这种情况下不凑效,另外,好多都是Linux下的,试了好久,最后的原因竟然相当简单:MySQL服务没起来. 因为对mysql.sock文件不是很熟,刚开始很大的时间都浪费在了这上面,重装后都不行,后来进入/usr/local/mysql/bin/下使用mysqld启动,出现下面的问题 好吧,我用root启动,结果又出现 Please read "Security" section of the manual to find out ho