View the mysql installation and running path
ps -ef | grep mysql

/usr/local/mysql/libexec/lib: operating path
–basedir=/usr/local/mysql/: installation path
-datadir=/usr/local/mysql/: The storage path of the database file
cd /usr/local/mysql/

vi my.cnf
Insert in my.cnf
skip-grant-tables

Save after editing
Restart mysql service
service mysqld restart
Change root password
After restarting, execute mysql -uroot -p (Enter directly without a password) to enter the mysql command line

Change Password
update mysql.user set password=PASSWORD('your-new-passwd') where User='root';

- Re-execute vi /etc/my.cnf, then delete the skip-grant-tables just added, and restart mysql
No Comments