LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-25-2011, 03:00 AM   #1
DarkSlayer
Member
 
Registered: Apr 2008
Location: Tbilisi , Georgia
Distribution: Fedora, CentOS
Posts: 65

Rep: Reputation: 19
Question Can't connect to MySQL after changing data and socket dirs


Hello

Centos 6, mysql 5.1.52-1.el6_0.1

I wanted to change my datadir from /var/lib/mysql to /home/mysql
as well as to put socket file to /var/run/mysqld
Here my configs and error
where should i change path else to get it working ?

Code:
# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Code:
# netstat -tulpn | grep mysql*
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1576/mysqld
my.cnf
Code:
[mysqld]
datadir=/home/mysql
socket=/var/run/mysqld/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
collation-server=utf8_general_ci

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysql.sock
edited daemon script as well /etc/rc.d/init.d/mysqld
Code:
get_mysql_option mysqld datadir "/home/mysql"
datadir="$result"
get_mysql_option mysqld socket "/var/run/mysqld/mysql.sock"
socketfile="$result"
New socket file is being created in proper dir i want to.
Yes i have restarted service as well as whole machine.
Why does it still trying to read sock file in old location ? Where should i change this setting ?
 
Old 08-25-2011, 03:13 AM   #2
DarkSlayer
Member
 
Registered: Apr 2008
Location: Tbilisi , Georgia
Distribution: Fedora, CentOS
Posts: 65

Original Poster
Rep: Reputation: 19
Solved.
Had to change client part of mysql as well.

Code:
[client]
socket=/var/run/mysqld/mysqld.sock
 
1 members found this post helpful.
Old 04-25-2012, 12:49 AM   #3
tquang
Member
 
Registered: Jul 2010
Posts: 44

Rep: Reputation: 0
Quote:
Originally Posted by DarkSlayer View Post
Solved.
Had to change client part of mysql as well.

Code:
[client]
socket=/var/run/mysqld/mysqld.sock
Thanks DarkSlayer very much, I finding that!
 
Old 04-26-2012, 09:08 AM   #4
DarkSlayer
Member
 
Registered: Apr 2008
Location: Tbilisi , Georgia
Distribution: Fedora, CentOS
Posts: 65

Original Poster
Rep: Reputation: 19
Wink

After that for proper work of PHP with mysql mysqli you have to change some strings in php.ini:

Code:
mysql.default_socket =
and
mysqli.default_socket =
also i haven't figure out how to configure mysql socket for already installed PDO extension. so if in some app especially if they are relay upon PDO you have to write 127.0.0.1 instead of "localhost"

Quote:
Originally Posted by tquang View Post
Thanks DarkSlayer very much, I finding that!
 
1 members found this post helpful.
Old 05-05-2012, 10:15 AM   #5
cartier247
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
Could I hire you to fix my error?

"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"
 
Old 04-02-2013, 04:23 AM   #6
sinichi33
LQ Newbie
 
Registered: Feb 2013
Posts: 1

Rep: Reputation: Disabled
Hi, just wanna share, today I fixed the problem with this error message : "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"

the problem was with the permission of mysql user , the new datadir path I set is /new/data

first I only set the permission to the designated folder only : chown mysql:mysql /new/data, then error occurred.

I fixed the issue by set the correct user (mysql) to the folder /new , I set chown mysql:mysql /new, please try. Thanks
 
  


Reply

Tags
directory, error, linux, mysqld, socket


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 03:13 PM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Software 3 06-28-2007 12:46 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 04:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 09:44 AM


All times are GMT -5. The time now is 06:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration