cyprich.com

By

How to Create Root Password in MySQL 8

One of the most frustrating things is installing MySQL and then forgetting what password you set for the root user. This has happened to me on more than one occasion. You can reset the password with the following procedure.

If you run mysqld and get errors where it can’t find a ..\data folder, run the following command:

mysqld –initialize

Create a text file (mysql-init.txt) with the following:

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘password‘;

Stop the MYSQL service. In Windows this is by running services.msc and right clicking on the MYSQL service and stopping it. Run the following command to reset the password:

mysqld –init-file=c:\mysql-init.txt

This will reset the password that you specified in the mysql-init.txt. Start the MYSQL service that you stopped and then login to test with:

mysql -u root -p

This will prompt you to enter the password for the root user that you just set. If all goes well, you’ll be running the MySQL command line interface and you can start running commands.

 

Leave a Reply

Your email address will not be published. Required fields are marked *