Xampp: cannot connect to mysql from terminal

I added export PATH=$PATH:/opt/lampp/bin/ to my ~/.zshrc file. I can access php but whenever I type sudo mysql -uroot I see the following message:

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

I can however, access mysql by defining full path like this: sudo /opt/lampp/bin/mysql -uroot. But I don't want that... I mean I would have to type the full path everytime or create an alias or symlink.

I am on Ubuntu 16.04 and using zshell.

2

1 Answer

You have two versions of mysql installed - one from Ubuntu repositories and one from some third party location. When you use the Ubuntu version, located in /usr/bin/mysql it attempt to connect trough a socket in the default location, /var/run/mysqld/mysqld.sock, which does not work, because the server running is not the Ubuntu stock mysql-server.

It works when you run /opt/lampp/bin/mysql -uroot (no reason to run that as root, by the way), because this mysql binary has default path set to where the actual socket is.

You have three alternatives:

  1. Modify your path so that /opt/lampp/bin/ is before/usr/bin/` in path. This will execute the lampp version of mysql before the Ubuntu version.
  2. Uninstall Ubuntu mysql client with sudo apt-get remove mysql-client. This may break other packages.
  3. Uninstall lampp and install the required packages from Ubuntu.

#3 would be my preferred solution. Getting all the software from the repositories ensures that it will be kept up to date, be (mostly) compatible, and have a clear, well defined upgrade path to the next Ubuntu Release.

Apache, PHP, Mysql/MariaDB and a lot of apache modules are available in the Ubuntu repositories.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like