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
- Create column after a column in existing table using query in MySQL
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Create Employee table in MySQL
- Get data in random order with limit from table using mysql
- How to get yesterday's date in MySQL ?
- How to create view in MySQL database
- Self join in mysql employee manager example
- How to show database tables in mysql using command line
- Create Index in MySQL with example
- How to create a new table from existing table in SQL
- How to check column exists or not in table using MySQL
- Change existing MySQL table column id to autoincrement
- How to check the MySQL version
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to retrieve data from two tables with one SQL statement
- How to get the list of all constraints in MySQL database
- Get number of connections being used by a specific user in MySQL
- How to create function in MySQL ?
- Check constraint in MySQL
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Get create table Query from existing table in phpMyAdmin
- How to Rename column name in MySql ?
- SQL query to delete records older than 6 months
- Get comma separated ids from table using MySQL
- Difference between SQL and NoSQL databases