The most reliable way to check MySQL installation is through your Linux distribution's package manager. Here are commands for different package managers:
# For Debian/Ubuntu systems
dpkg -l | grep mysql
# or
apt list --installed | grep mysql
# For RHEL/CentOS systems
rpm -qa | grep mysql
# or
yum list installed | grep mysql
If MySQL is installed, you can verify its service status:
systemctl status mysql
# or for older systems
service mysql status
Active status indicates MySQL is both installed and running. If you see "Unit mysql.service could not be found," MySQL might not be installed.
Attempting to connect via MySQL client can reveal installation status:
mysql --version
# If installed, returns version info like: mysql Ver 8.0.33 for Linux on x86_64
# Try connecting to server
mysql -u root -p
Look for running MySQL processes:
ps -ef | grep mysql
# or
pgrep mysqld
MySQL creates specific directories during installation. Check their existence:
ls /var/lib/mysql # Data directory
ls /etc/mysql # Configuration directory
ls /usr/bin/mysql* # Binary files
For more comprehensive checks:
# Check installed files from package
dpkg -L mysql-server # Debian/Ubuntu
rpm -ql mysql-server # RHEL/CentOS
# Search for mysql binaries
which mysql
whereis mysql
Remember that MySQL might be installed under different package names like mariadb-server on some distributions. Always check your distribution's documentation for specific package names.
html
When working with Linux servers, there are several reliable methods to check for MySQL installation:
# Method 1: Check MySQL service status
systemctl status mysql
# Alternative for older systems:
service mysql status
# Method 2: Check installed packages
dpkg -l | grep mysql
# For RPM-based systems:
rpm -qa | grep mysql
# Method 3: Check MySQL version
mysql --version
Even if MySQL is installed, it might not be running. Verify active processes:
ps aux | grep mysql
# Check port 3306 (default MySQL port)
netstat -tulnp | grep 3306
# Modern alternative:
ss -tulnp | grep mysql
The most definitive test is attempting to connect to the MySQL server:
mysql -u root -p
# If you get a password prompt, MySQL is installed and running
# For quick check without password:
mysqladmin ping
MySQL leaves configuration traces even when not running:
# Common configuration file locations
ls -l /etc/mysql/
ls -l /etc/my.cnf
ls -l ~/.my.cnf
# Common installation directories
ls -l /usr/bin/mysql*
ls -l /usr/sbin/mysqld
ls -l /var/lib/mysql/
Here's a bash script that combines these checks:
#!/bin/bash
echo "=== MySQL Installation Checker ==="
echo -n "Checking MySQL service: "
systemctl is-active mysql >/dev/null 2>&1 && echo "Active" || echo "Inactive"
echo -n "Checking MySQL version: "
mysql --version 2>/dev/null || echo "Not found"
echo "Checking open ports:"
ss -tulnp | grep mysql
echo "Checking installed packages:"
dpkg -l | grep -i mysql || rpm -qa | grep -i mysql
echo "Testing connection:"
mysqladmin ping 2>/dev/null || echo "Unable to connect"