English
+370 5 205 5502 sales@monovm.com

In today's article, we will explore what are databases, as well as provide you with a short tutorial on how to reset the root password in MySQL.

23

Sep, 20

MySQL Tutorial: Resetting the Root Password

There are many different database services out there and MySQL is one of the more popular ones. It is a part of some of the most used stacks out there such as LAMP (i.e. Linux, Apache, MySQL, PHP), WAMP (i.e. Windows, Apache, MySQL, PHP), and MAMP (i.e. macOS, Apache, MySQL, PHP). By definition, it is an open-source relational database management system (RDBMS) with a client-server model. Let us get into a bit more detail about what exactly is a database.

 

What is a Database?

Put simply, a database is just a collection of structured data. It is generally stored on a server and can be accessed remotely with a computer. Think of it like an organized photo album, where each photo is an entry into the database while the entire album is the database itself.

 

How to Reset the MySQL Root Password?

The root password for a MySQL database allows the root user to have full access to the database. In order to reset this password, you should have root or administrative access to the server.

  1. First, you have to stop the MySQL service by writing the following command into the terminal

CentOS:

sudo /etc/init.d/mysqld stop

Debian/Ubuntu:

sudo /etc/init.d/mysql stop

  1. Then, you have to start the service without a password with the command:

sudo mysqld_safe --skip-grant-tables &

  1. Connect to MySQL by running the following command:

mysql -uroot

  1. Run the following command to set a new MySQL root password:

use mysql;

update user set authentication_string=PASSWORD("mynewpassword") where User='root';

flush privileges;

quit

Note that in the "mynewpassword" field, you should enter the new desired password.

  1. Now restart the MySQL service by running the following commands:

CentOS:

sudo /etc/init.d/mysqld stop

sudo /etc/init.d/mysqld start

Debian/Ubuntu:

sudo /etc/init.d/mysql stop

sudo /etc/init.d/mysql start

  1. The new password should now be set. Test it by logging in to the database with it:

mysql -u root -p

After running the command above, you should be prompted to enter a password. Type in the newly set password to check if it works.

 

 

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com