1

i try to connect to mysql server but it gives me socket issue i have edited my.cnf from /var/lib/mysql/mysql.sock to /home/mysql/mysql.sock Nb: the issue exist before moving mysql db file to the new directory.

[root@dc ~]# /usr/bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


[root@dc ~]# ps aux | grep mysqld
root      8472  0.0  0.0 108216  1596 pts/2    S    10:18   0:00 /bin/sh  /usr/bin/mysqld_safe --datadir=/home/mysql --socket=/home/mysql/mysql.sock --pid-       file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
 mysql     8691  0.1  0.0 543468 47860 pts/2    Sl   10:18   0:00   /usr/libexec/mysqld --basedir=/usr --datadir=/home/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/home/mysql/mysql.sock
root      8825  0.0  0.0 103356   852 pts/2    S+   10:20   0:00 grep mysqld

Mysqld directive under my.cnf:

[mysqld]
datadir=/home/mysql
socket=/home/mysql/mysql.sock
Omer Stimpack
  • 205
  • 1
  • 3
  • 12

3 Answers3

2

Have you verified that the file /home/mysql/mysql.sock exists and is readable etc?

I've seen this in the past where there is right issues and the file doesn't get created or cannot be accessed.

Also, are there any errors in the logs when you do a '/etc/init.d/mysqld restart'*?

// Mike *or whatever your OS wants for a restart of the daemon/service

Swedish Mike
  • 121
  • 4
  • /etc/init.d/mysqld restart correctly the out of mysqld.log: 151111 10:45:22 [ERROR] Native table 'performance_schema'.'events_waits_summary_global_by_event_name' has the wrong structure 151111 10:45:22 [ERROR] Native table 'performance_schema'.'file_summary_by_event_name' has the wrong structure 151111 10:45:22 [ERROR] Native table 'performance_schema'.'file_summary_by_instance' has the wrong structure 151111 10:45:22 [ERROR] Native table 'performance_schema'.'mutex_instances' has the wrong structure 151111 10:45:22 [ERROR] Native table – Omer Stimpack Nov 11 '15 at 15:46
  • [ERROR] Native table 'performance_schema'.'file_summary_by_instance' has the wrong structure 151111 10:45:22 [ERROR] Native table 'performance_schema'.'mutex_instances' has the wrong structure [ERROR] Native table 'performance_schema'.'rwlock_instances' has the wrong structure 151111 10:45:22 [ERROR] Native table 'performance_schema'.'cond_instances' has the wrong structure – Omer Stimpack Nov 11 '15 at 15:47
  • @OmerStimpack it looks like you are using data from a different version of mysql than you are running. The safe way to deal with this is do a dump with the version you were running before and then reload it into the new version. – chicks Nov 12 '15 at 02:26
2

Try to add the socket to the my.cnf in the client directive.

[mysql]

# CLIENT #
port                            = 3306
socket                          = /home/mysql/mysql.sock

[mysqld_safe]

socket                          = /home/mysql/mysql.sock
nice                            = 0

[mysqld]

# GENERAL #
user                            = mysql
default-storage-engine          = InnoDB
pid-file                        = /var/run/mysqld/mysqld.pid
socket                          = /home/mysql/mysql.sock
Remko
  • 36
  • 4
  • already added to my.cf [mysqld] datadir=/home/mysql socket=/home/mysql/mysql.sock – Omer Stimpack Nov 11 '15 at 16:01
  • Yes but you need to add it under the [mysql] directive as well, i'll update my comment for more detail – Remko Nov 11 '15 at 16:02
  • i can log with ssh now to mysql but when i use phpmyadmin it says: Cannot log in to the MySQL server – Omer Stimpack Nov 11 '15 at 16:20
  • My guess is that PHPMyAdmin tries to connect using host based connection. Add the socket to your phpmyadmin config: $cfg['Servers'][$i]['socket'] = '/home/mysql/mysql.sock'; See: https://phpmyadmin-english-united-kingdom.readthedocs.org/en/latest/config.html#cfg_Servers_socket – Remko Nov 11 '15 at 16:24
  • config.inc.php edited i added my new directory $cfg['Servers'][$i]['socket'] = '/home/mysql/mysqld.sock' and restarted httpd but is still not working – Omer Stimpack Nov 11 '15 at 16:39
1

your ps output shows, that the socket of your mysqld is stored in:

/home/mysql/mysql.sock

but your mysql client tries the default of:

/var/lib/mysql/mysql.sock

So you could try:

/usr/bin/mysql -u root -p -S /home/mysql/mysql.sock
randomcontrol
  • 260
  • 2
  • 5
  • yes it works but how can i make my.cf recognize because i already add /home/mysql/mysql.sock in mysql config file because i cant access to phpmyadmin – Omer Stimpack Nov 11 '15 at 15:49