Search code examples
mysqlsudo

Connect to local MySQL server without sudo


This command:

mysql -uroot -p

Gives the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

But running the same with sudo privileges, works:

sudo mysql -uroot -p

My MySQL Server installation is a custom one, as i needed the 5.1 version, so i downloaded the RPM from the official website, converted it to deb using alien, and installed it with dpkg. The file named: /var/lib/mysql/mysql.sock exists, but it's owner is the mysql user.

Please, how could i get rid of the sudo requirement?

Ubuntu 14.04 MySQL Server 5.1.73 MySQL Client 5.5.37


Solution

  • You need to change the permissions to /var/lib/mysql/ and the sock file to let it be readable by other users than root. You can try this one:

    sudo chmod -R 755 /var/lib/mysql/