Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant connect to Mysql server ; Can't create/write the pid file

Tags:

database

mysql

Hello I cant seem to connect to my mysql server, i get the following error

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

when i checked the logs , it showed me the following :

130314 12:36:16 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'plugin' is read only
130314 12:36:16 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
130314 12:36:16  InnoDB: Initializing buffer pool, size = 8.0M
130314 12:36:16  InnoDB: Completed initialization of buffer pool
130314 12:36:16  InnoDB: Started; log sequence number 13 1336891001
130314 12:36:16 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/lib/mysql/live.pid' (Errcode: 13)
130314 12:36:16 [ERROR] Can't start server: can't create PID file: Permission denied
like image 265
Nauman Bashir Avatar asked Mar 14 '13 11:03

Nauman Bashir


People also ask

Can not connect to server MySQL?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

Where is MySQL pid file?

To check the PID file for the mysqld node: the default location for it is the data directory of the node, specified by the datadir option in either a configuration file or at the command line at the start of the mysqld process.

Can not connect to MySQL server through socket?

Try to connect to 127.0.0.1 instead of localhost If you connect to localhost , it will use the socket connector, but if you connect to 127.0. 0.1 the TCP/IP connector will be used. So when the socket connector is not working, try connecting to 127.0. 0.1 instead.


2 Answers

I had sample problem with mysql. I run under root permission but don't known why this error happen. The problem is mysql user don't have permission to create pid file in /var/run/mysqld. Full log could look like:

140812 09:35:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140812  9:35:53  InnoDB: Initializing buffer pool, size = 8.0M
140812  9:35:53  InnoDB: Completed initialization of buffer pool
140812  9:35:53  InnoDB: Started; log sequence number 0 197396648
140812  9:35:53 [ERROR] /usr/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13)
140812  9:35:53 [ERROR] Can't start server: can't create PID file: Permission denied
140812 09:35:53 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

So the solution is assign mysql user to this directory:

# chown mysql:mysql /var/run/mysqld

and then start mysqld

# service mysqld start
like image 153
Khai Nguyen Avatar answered Sep 21 '22 10:09

Khai Nguyen


I had the same problem under Redhat and this page had the steps to switch the mysql directory.

service mysqld stop
mkdir /srv/mysql/
chown mysql:mysql /srv/mysql

edit /etc/mysql/my.cnf and set datadir=/srv/mysql & socket=/srv/mysql/mysql.sock

Additional steps are required if you are using SELinux and then finally start the server

service mysqld start
like image 39
Sumit Avatar answered Sep 19 '22 10:09

Sumit