First you need to log in to the server where MySQL is installed
1. Stop the MySQL service
# Service Mysqld Stop
(My server is using the compilation installed MySQL, did not find the corresponding mysqld, I directly use the kill process to kill MySQL)
2. Skip the Startup authorization form and start MySQL
There are two ways of doing this:
1. Modify MY.CNF (My.ini)
# The MySQL server[mysqld]port 3306 Socket =/var/lib/mysql/mysql.sock#add line#skip-grant-tables
2. Start Mysqld_safe and skip the start authorization form. The Skip-grant-tables parameter at startup is designed to not start the Grant-tables, authorization table when MySQL is started. This will allow you to change the root password.
# Mysqld_safe--skip-grant-tables &
3. Log in to MySQL and change the password
1 mysql-uroot-p ---- require a password, you can enter it directly. 2usemysql; 3 set password=password ('12345678'where user="Root "; --- set the root password to 123456784flush privileges; 5 quit
4. Kill the Mysqld_safe process and restart the mysqld.
Service mysqld Start
My server is in/usr/bin/mysqld_safe.
MySQL forgot root password