Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have this weird problem after changing the MySQL datadir location from default "/var/lib/mysql" It was working yesterday, but today I get "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'," a typical message if the daemon is not running and it's looking for the socket file in the old datadir location.

I changed the my.cnf file and mysqld file to point to the new location, NEW_DIR. The daemon runs, but I cannot open mysql.

Thanks in advance.

# cat /etc/my.cnf
[mysqld]
datadir=/NEW_DIR/mysql
socket=/NEW_DIR/mysql/mysql.sock

# cat /etc/init.d/mysqld | grep datadir
get_mysql_option mysqld datadir "/NEW_DIR/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"

# /etc/init.d/mysqld start
Starting MySQL:                                            [  OK  ]

# tail mysqld.log 
120203 11:12:20  mysqld started
120203 11:12:20  InnoDB: Started; log sequence number 0 43655
120203 11:12:20 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.77'  socket: '/NEW_DIR/mysql/mysql.sock'  port: 3306  Source distribution

# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
share|improve this question

migrated from stackoverflow.com Feb 7 '12 at 19:14

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 5 down vote accepted

The problem is the mysql client program configuration. You can specify the --socket=/NEW_DIR/mysql/mysql.sock command-line option or add it under the [mysql] section of your my.cnf file.

Please look at the documentation for specifying options through option files: http://dev.mysql.com/doc/refman/5.0/en/option-files.html

Since changing the socket path affects all the client programs, then it will make sense to update the global my.cnf and set the socket option under the [client] section.

share|improve this answer
    
Ok. Adding --socket=/NEW_DIR/mysql/mysql.sock does work, but I have added it under [mysql] section in my.cnf as shown in my original post (socket=/NEW_DIR/mysql/mysql.sock), but it still doesn't work. –  user173457 Feb 3 '12 at 19:59
    
@Xint0 it works now after adding socket under [client]. Many thanks! –  user173457 Feb 4 '12 at 0:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.