SystemsKalilinux

How to Install MySQL on Kali Linux

Kali ships with MariaDB, and it conflicts with MySQL. Here is the sequence that finally worked for me.

Kushan Manahara

March 4, 2023 · 2 min read

0356
How to Install MySQL on Kali Linux

Installing MySQL on Kali Linux can be a challenging task, and I struggled with it multiple times. I kept at it and spent considerable time finding a solution, and eventually got it working. This is the sequence that worked.

Try the normal way first

Update the system, then attempt the standard install:

terminal.sh
sudo apt update
sudo apt install mysql-server

If that fails, download the MySQL APT configuration package and continue below:

terminal.sh
wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb

Remove MariaDB first

The install often will not succeed on a fresh system, because Kali Linux comes with MariaDB as its default database management system and the two conflict. MariaDB has to go first.

The conflict is not arbitrary. MariaDB started as a fork of MySQL, so both packages want to own the same binary names, the same default data directory at /var/lib/mysql, and the same port 3306. apt will not let two packages claim the same files, which is why the install fails rather than warning you.

Stop and disable the MariaDB server:

terminal.sh
sudo systemctl stop mariadb
sudo systemctl disable mariadb

Then remove it:

terminal.sh
sudo apt remove mariadb-server mariadb-client

Then purge it. On Kali, purge removes a package along with its configuration files, which remove leaves behind:

terminal.sh
sudo apt purge mariadb-server mariadb-client

Then run autoremove, which clears out packages that were installed as dependencies for something else and are no longer needed:

terminal.sh
sudo apt autoremove

Install MySQL

With MariaDB gone, the install goes through:

terminal.sh
sudo apt install mysql-server

Check it actually worked

Installing the package is not the same as having a running server, and it is worth confirming which of the two you have before you go looking for problems elsewhere:

terminal.sh
sudo systemctl status mysql
mysql --version

If it is not running, start it and have it come up on boot:

terminal.sh
sudo systemctl start mysql
sudo systemctl enable mysql

A fresh install ships with permissive defaults. The bundled hardening script walks through setting a root password and removing anonymous accounts, the test database, and remote root login:

terminal.sh
sudo mysql_secure_installation

Then confirm you can actually get in:

terminal.sh
sudo mysql -u root -p

If something still fails after all this, the log is more useful than guessing. sudo journalctl -u mysql -n 50 will usually name the problem outright, and leftover MariaDB files in the data directory are the most common cause.

Written by

Kushan Manahara

Responses (0)

Verified name, role, and email required before posting.

No responses yet

Be the first to share your thoughts, benchmarks, or feedback above.