In today’s article, we’ll explore what databases are, as well as provide you with a short tutorial on how to change the MySQL root password. There are many different type database services out there. Now MySQL is one of the most popular ones. It is a part of some of the most widely used stacks such as LAMP. [ie Linux, Apache, PHP, MySQL], WAMP [ie Windows, Apache, PHP, MySQL], and MAMP [ie macOS, Apache, PHP, MySQL]. By definition, is an open-source relational database management system (RDBMS) with a client-server model. Let’s go into a little more detail about what a database actually is.
First, we have to know what is a database?
Simply put, a database is a collection of structured data. It is usually stored on a server and can be accessed remotely through a computer. Think of it like an organized photo album, where each photo is an entry in the database and 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 full access to the database. For changing this password, you should have root or administrative access to the server.
First, you need to stop the MySQL service by typing the following command in the terminal
CentOS:
sudo /etc/init.d/mysqld stop
Debian/Ubuntu:
sudo /etc/init.d/mysql stop
After that, you have to start the service without a password with the command:
sudo mysqld_safe –skip-grant-tables &
You have to Connect to MySQL by running the following command:
mysql -uroot
You have to 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.
Now you have to 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
The new password should now be set. You have to try it by logging in to the database with it:
mysql -u root -p
After running the above command, you should be prompted to enter a password. Type the newly set password to check if it works.



