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:
- 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.
- Uninstall Ubuntu mysql client with
sudo apt-get remove mysql-client
. This may break other packages.
- 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.
sudo
uses its ownsecure_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