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
- Self join in mysql employee manager example
- How to get a list of MySQL views?
- How to show database tables in mysql using command line
- Insert multiple rows in a single MySQL query
- How to get the list of all constraints in MySQL database
- How to create function in MySQL ?
- Clear the terminal screen in MySQL within the Windows powershell
- SQL query to delete all rows older than 30 days
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to get yesterday's date in MySQL ?
- MySQL create procedure example
- Create column after a column in existing table using query in MySQL
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Get data in random order with limit from table using mysql
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Create Employee table in MySQL
- Create Index in MySQL with example
- How to check column exists or not in table using MySQL
- How to create view in MySQL database
- How to check the MySQL version
- Database connection using mySQLi with object-oriented
- How to create a new table from existing table in SQL
- How to retrieve data from two tables with one SQL statement
- Get create table Query from existing table in phpMyAdmin
- Change existing MySQL table column id to autoincrement