I installed XAMPP on Ubuntu 18.04, ran /opt/lampp/lampp start and all the services started successfully. However, when I try to run mysql -u root -p I get this error:

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

If I try to run sudo service mysql start, I get this error: "Failed to start mysql.service: Unit mysql.service not found."

I have uninstalled and reinstalled XAMPP. I can still access phpMyAdmin and display the index.html on the browser. I've also read several other posts with similar titles, but none of the proposed solutions has fixed my issue.

2 Answers 2


If you want to run the XAMPP`s mysql you should run:

/opt/xampp/bin/mysql instead of mysql

The error may be because you already have mysql package installed via apt

NB: XAMPP includes MariaDB not MySQL


This error in my case was caused by a previous MYSQL installation and a subsequent XAMPP installation, these two conflict with each other as there are two MYSQL fighting for listener port etc.

The solution in my case was:

Stop MYSQL initial install (not the XAMPP)

$> systemctl status mysql.service   ## Check the status 

$> systemctl stop mysql.service     ## Stop the service

Start MYSQL from XAMPP

$> sudo /opt/lampp/lampp startmysql  # to start the XAMPP mysql  
$> /opt/lampp/bin/mysql              # connect to XAMPP mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g. Your
MariaDB connection id is 9 Server version: 10.4.11-MariaDB Source

........... This time didn't ask for password


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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