3

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

Hunor Kovács
  • 503
  • 5
  • 13
  • Possible duplicate of [Connect to mysql server without sudo](https://stackoverflow.com/questions/37239970/connect-to-mysql-server-without-sudo) – Keet Sugathadasa May 18 '19 at 05:13

2 Answers2

8

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/

vnd
  • 244
  • 1
  • 5
  • Didn't help. The socket file was already with all permissions to all users. – Hunor Kovács Jun 29 '14 at 20:27
  • Ok, just try to analize all of the directories down in the path of the socket file, they need to have o+rx and the sock file too (it's not a good idea to make it modifiable by others). You can also try to remove mysql.sock and then restart mysqld, the file should be created by the daemon with proper privileges. – vnd Jun 29 '14 at 20:35
  • 2
    Ok, restarted the service, i mean i rebooted, and now it works. :) – Hunor Kovács Jun 29 '14 at 20:46
-4

I don't think you can since the user you specify with the -u option is root. To be root you need sudo. You can try creating another user. That way you shouldn't need sudo.

wahiddudin
  • 103
  • 6
  • 3
    There is no connection between the mysql user `root` and the operating system's `root` or `sudo`. It's 100% possible for a regular system user to connect to mysql as `root`. – grossvogel Jun 29 '14 at 20:20