What is the MySQL root password in Kali Linux. How to change/reset MySQL root password in Kali Linux

How to set root password to start using MySQL

For a newly installed MySQL, the root user password is empty. 

You can log into MySQL (MariaDB) with the following command without even entering your password:

sudo mysql -u root

To set the root password run and follow the instructions:

sudo mysql_secure_installation

Let's take a close look at everything this script tells us, since we need to pay special attention to the security of the server.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here.
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n

Change the root password? [Y/n]

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? [Y/n]

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]

By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? [Y/n]

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? [Y/n]

All done! If you've completed all of the above steps, your MariaDB installation should now be secure.

Once again about the MariaDB password. This must be a strong and unique password. Think of it as your server login password. It must be different from the Linux user's password.

How to allow root user to connect to MySQL and MariaDB without sudo

To access the MariaDB database as a regular user without using sudo privileges, go to the MySQL command line prompt

sudo mysql 

and run the following commands:

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
exit

Please note that you need to enter the PASSWORD.

Then try logging into the database without sudo as shown below.

mysql -u root -p

Why this is happening and other options, see the article “Password and unix_socket authentication in MySQL and MariaDB. Error “#1698 - Access denied for user ‘root’@’localhost’” (SOLVED)”.

How to reset a forgotten MySQL password

If you suddenly forgot (or did not know) the MySQL password in Kali Linux, then this instruction will help you reset (replace with a new one), but not find out the root password. If this suits you, then in the first terminal type:

sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables

In another terminal

mysql -u root mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
FLUSH PRIVILEGES;
quit

Please note that the NEW_PASSWORD line needs to be replaced with the password you want to set for root MySQL.

In the first terminal CTRL+C or in any terminal:

sudo kill `sudo cat /var/run/mysqld/mysqld.pid`

And then:

sudo systemctl start mysql

That's it, now your MySQL password is new.

By the way, this method will work fine on any Linux, not just Kali Linux. But keep in mind that the commands for starting and stopping services on different Linux may differ. The commands given here will work unchanged for Debian derivatives (Mint, Ubuntu).

Recommended for you:

Leave a Reply

Your email address will not be published. Required fields are marked *