Steps under Windows platform
1. Log in to the windows system as an administrator
2. Use the windows service management tool or task manager to stop the MySQL service
3. Create a single-line text file , save it as c:mysqlpwdhf.txt,
the content is SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
4. Open a console window and get the DOS command prompt
5. Assume that your The MySQL home directory is C:/mysql/bin,
then run c:mysqlbinmysqld-nt --init-file=c:mysqlpwdhf.txt.
If the MySQL database server is installed using the installation wizard, then You need to make changes through the service management tool.
You need to find and add the default settings file,
and then run mysqld-nt --defaults-file="pathmy.ini" --init-file=c:mysqlpwdhf.txt
6 .Stop the MySQL database service, and then restart MYSQL in normal mode
7. You can log in to the server normally.
Steps in Unix environment
1. Log in to the system as root or the user who started the mysqld process
2. Find and locate the process containing the Mysql service The file number is .pid, which may be
in /var/lib/mysql/,/var/run/mysqld/,/usr/local/mysql/data/, and
the file name is generally in the format of "machine name.pid". Use the command kill 'cat /mysql-data-directory//host-name.pid' under the shell
to end the mysql service process
3. Create a single-line text file, which can be named arbitrarily, assuming it is mysql-init, and
save it in the user's home directory ~ can be downloaded,
the file content is SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
4. Re-start mysql with options, the specific command is mysqld_safe --init-file=~/mysql-init & ,
the mysql-init file should be deleted after normal operation
5. You can use the new password to connect to the database.
General solution:
- Use the client interactive tool mysql to set up. The steps are as follows:
1. Stop the mysql service and re-
start the mysql service with the --skip-grand-table --user=root option (it can be omitted under windows - -user=root option)
2. Use the client interactive tool mysql to connect to the server, shell>mysql -u root
3. Execute the following statements in the client interactive tool mysql:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd' )
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
4. You can use newpwd as the password to log in to the server.