question about socket

Question to Percona Support:


Hello, Dear Percona

I download the Percona-Server-5.6.14-rel62.0-483.Linux.x86_64.tar from the percona.com.

When I tar this file and try to execute the mysql command, it gives me the error
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

But in my my.cnf, I set the sock=/var/lib/mysql/mysql.sock.

I know that if I make a link-file to point this real socket file in the /var/lib/mysql dir can reslove this problem.

But I want to know how the /app/mysql/bin/mysql to executed. Why it find the socket file from the /tmp dir.

Is this can be configure in the Percona or in the RedHat System?

Below is my uname -a result:
2.6.32-262.el6.x86_64 #1 SMP Sun Apr 8 18:38:00 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

I am waiting for your apply, thanks a lot!


李宋高

Hi,

The default socket path for MySQL 5.6 is ‘/tmp/mysql.sock’.
http://dev.mysql.com/doc/refman/5.6/…_mysqld_socket

So if you have non-default socket place specified in my.cnf ([mysqld] section) then you can connect to mysql by the following ways:

  • specify socket explicitly in connection string:
    mysql -u root -p -S /var/lib/mysql/mysql.sock

OR

  • add the socket info to [client] section in my.cnf (and restart mysql) so your config file will be looking like below:
    [mysqld]

    socket = /var/lib/mysql/mysql.sock

[client]

socket = /var/lib/mysql/mysql.sock

In this case you’ll be able to connect w/o specifying socket, like below:
mysql -u root -p

That’s because:

  • socket in [mysqld] - the path where server will place a .sock file
  • socket in [client] - the path where will be looking for .sock file while connecting

By default both variables are ‘/tmp/mysql.sock’

You can read more related info there:
[URL=“MySQL :: MySQL 5.6 Reference Manual :: 4.2.2.2 Using Option Files”]http://dev.mysql.com/doc/refman/5.6/...ion-files.html[/URL]

Hi, Dear Michael

I am Li, thanks for your apply.

I didn’t find any .my.cnf in my Percona basedir, even all of my / dir.
[root@MYSQL_01 mysql]# find / -name ‘.my.cnf’
[root@MYSQL_01 mysql]#

It seams the strace output is null.
[root@MYSQL_01 bin]# pwd
/app/mysql/bin
[root@MYSQL_01 bin]# strace -f -e trace=open mysql 2>&1 | grep -i cnf
[root@MYSQL_01 bin]#

some logs…

###################################
my.cnf
###################################

[root@MYSQL_01 ~]# cat /app/mysql/my.cnf
[mysqld]
datadir=/app/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[client]
socket=/var/lib/mysql/mysql.sock

[mysqld_safe]
log-error=/app/mysql/mysqld.log
pid-file=/app/mysql/mysqld.pid

###################################
process:
###################################
[root@MYSQL_01 ~]# ps -ef | grep mysqld
root 3425 1 0 05:07 pts/0 00:00:00 /bin/sh /app/mysql/bin/mysqld_safe --datadir=/app/mysql/data --pid-file=/app/mysql/data/MYSQL_01.pid
mysql 3591 3425 10 05:07 pts/0 00:00:00 /app/mysql/bin/mysqld --basedir=/app/mysql --datadir=/app/mysql/data --plugin-dir=/app/mysql/lib/mysql/plugin --user=mysql --log-error=/app/mysql/mysqld.log --pid-file=/app/mysql/data/MYSQL_01.pid --socket=/var/lib/mysql/mysql.sock
root 3618 3103 0 05:07 pts/0 00:00:00 grep mysqld

###################################

BUT:
[root@MYSQL_01 ~]# mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

Hi Li,

Can you try to move my.cnf to default place (/etc/my.cnf) and restart mysql?
Just to try if this will be helpful.

OR

You can also try the following:

sudo -i
mysqld --defaults-file=/app/mysql/my.cnf &

then try to connect.

Hi, mixa

It seams you changed the name? Or maybe I was missing.
I delete the default /etc/my.cnf all ready for this test.
Maybe I think this is the OS problem. As you know, some packages maybe included in the OS.
When I executed mysql, may this bin file is not Percona’s mysql.
I will try to executed /app/mysql/bin/mysql and watch it’s out.

Thanks a lot for your help and be sorry for update so late.