List of content you will read in this article:
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.
- 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
- Then, you have to start the service without a password with the command:
sudo mysqld_safe --skip-grant-tables &
- Connect to MySQL by running the following command:
mysql -uroot
- 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 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. 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.