Forgot the password of mysql root, can not find the processing method of my.cnf in etc.

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

Comments

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注