Mysql – unable to connect to thesql database in Ubuntu

MySQLUbuntu

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.

Best Answer

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.