Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to connect to mysql database in Ubuntu

Tags:

mysql

ubuntu

I'm facing this problem for few days now. I'm trying to connect to my MySQL on Ubuntu machine. But I'm not getting this thru. Please see the following commands that I ran and the error messages.

root@ipadtest:/var/lib/mysql# mysql start

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysql -uroot -p

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysqld

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored 150821 11:34:38 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

150821 11:34:38 [ERROR] Aborting

150821 11:34:38 [Note] mysqld: Shutdown complete

root@ipadtest:/var/lib/mysql# mysql restart

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

root@ipadtest:/var/lib/mysql# mysqladmin -u root -p status

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored Enter password: mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

Could anyone please tell what is the issue. It seems to me that DB has been corrupted. If yes, then how can I recover? TIA.

like image 883
Indra Prakash Tiwari Avatar asked Aug 21 '15 06:08

Indra Prakash Tiwari


People also ask

Can't connect to local MySQL server Ubuntu?

To fix the MySQL socket issue and access denied error for root@localhost , follow the below steps. Stop the MySQL server by executing the command “ sudo service mysql stop “. Create socket location as a placeholder by executing the command “ sudo mkdir -p /var/run/mysqld “.


1 Answers

The error is very clearly explained in the warning message, it is ignoring your my.cnf.

Warning: World-writable config file '/etc/mysql/my.cnf' is ignored

Try executing the following, and then restarting the server

chown mysql:mysql /etc/mysql/my.cnf
chmod 600 /etc/mysql/my.cnf

This will set the owner of the file to mysql and the permissions 600 will give only the user mysql access to read and write to the file, it will disallow access to all other users.

like image 179
Matt Clark Avatar answered Oct 21 '22 14:10

Matt Clark