1

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.

  • 1
    Any particular reason to run XAMPP and not our native version? Ours is tailored to Ubuntu works out of the box and has lots more documentation. Plus the owner of XAMPP himself admitted that it is not fit for serious usage. – Rinzwind Feb 1 '18 at 8:29
  • sudo uses its own secure_path rather than the invoking user's path. Do you really need to run mysql as root (as opposed to logging in to it with the mysql root user)? – steeldriver Feb 1 '18 at 11:07
1

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.