Reset password for the root user in MySQL
Resetting the password for the root user in MySQL is an important step in securing your databases. By default, when you install MySQL, there is no root password set. This means that you can access the MySQL server as the root user without being prompted for a password.
To improve the security of your MySQL installation, it is recommended that you set a root password.
Reset password for root user using mysql shell command
Here is step by step guide to reset password for root user in MySQL.
Step 1 - Open terminal
Step 2 - Login to mysql shell using
mysql -u root -pcommand
mysql -u root -p
If you have set a root password, you will be prompted to enter that password.
Step 3 - Reset password for the root user
You can run the below command to change the password for the root user. Replace ‘new_password’ with the desired new password for the root user in the below statement.
Here we have two different method to reset the password for the root user. You can use any one of them.
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';
By using the caching_sha2_password plugin , you can improve the security and performance of your MySQL database, as well as increase compatibility with external applications.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Step 4 - FLUSH PRIVILEGES
You need to flush the privileges to ensure that the changes take effect. You can do this by executing the following SQL statement.
Step 5 - Quit Terminal
Finally, you can quit the MySQL client by executing the quit command.
Now you can login to MySQL server as the root user, you can use the following command in a terminal or command prompt:
mysql -u root -p
After running the command, you will be prompted to enter the password for the 'root' user that you set earlier. Once you have entered the correct password, you will be logged in to the MySQL server and will be able to run SQL commands.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- SQLSTATE: Warning: 1265 Data truncated for column 'visibility' at row 1
- Drop foreign id column (user_id) in MySQL
- Change existing MySQL table column id to autoincrement
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Get comma separated ids from table using MySQL
- Get create table Query from existing table in phpMyAdmin
- SQL query to delete all rows older than 30 days
- SQL query to delete records older than 6 months
- How to check column exists or not in table using MySQL
- MySQL create procedure example
- Check constraint in MySQL
- How to create a new table from existing table in SQL
- Database connection using mySQLi with object-oriented
- How to show database tables in mysql using command line
- How to retrieve data from two tables with one SQL statement
- Get data in random order with limit from table using mysql
- Insert multiple rows in a single MySQL query
- Create column after a column in existing table using query in MySQL
- How to check the MySQL version
- Cannot drop index 'fk_role_id': needed in a foreign key constraint