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 -p
commandmysql -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.
Or
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.
FLUSH PRIVILEGES;
Step 5 - Quit Terminal
Finally, you can quit the MySQL client by executing the quit command.
quit;
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
- Clear the terminal screen in MySQL within the Windows powershell
- How to Rename column name in MySql ?
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Get full name of a person in SQL using function
- Insert multiple rows in a single MySQL query
- How to create a new table from existing table in SQL
- How to drop function in MySQL ?
- Get create table Query from existing table in phpMyAdmin
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- MySQL create procedure example
- Drop foreign id column (user_id) in MySQL
- Check constraint in MySQL
- SQL query to delete all rows older than 30 days
- Database connection using mySQLi with object-oriented
- How to create view in MySQL database
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- How to get the list of all constraints in MySQL database
- Self join in mysql employee manager example
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to create function in MySQL ?
- Difference between SQL and NoSQL databases
- Change existing MySQL table column id to autoincrement
- How to retrieve data from two tables with one SQL statement
- Create column after a column in existing table using query in MySQL
- How to get a list of MySQL views?