mysql忘记密码后如何重置密码

macOS terminal

mysql 8.0

How to reset new password without old one

#1. stop mysql
/usr/local/mysql/support-files/mysql.server stop

#2.Run the server in safe mode with privilege bypass: 

sudo mysqld_safe --skip-grant-tables

#3.enter mysql
mysql -u root

#4.dont set password
> UPDATE mysql.user SET authentication_string=null WHERE User='root';

> FLUSH PRIVILEGES;

> \q


#set new password

mysql -u root

> ALTER USER 'root'@'localhost' IDENTIFIED BY '';

https://gist.github.com/zubaer-ahammed/c81c9a0e37adc1cb9a6cdc61c4190f52

Errors when resetting

I tried to launch it in safe mode, to which I received the following list of errors:

140131 00:03:02 mysqld_safe Logging to '/usr/local/var/mysql/david-mbp.err'.
140131 00:03:02 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
140131 00:03:03 mysqld_safe mysqld from pid file /usr/local/var/mysql/david-mbp.pid ended

The issue is caused by file permission

#check file permission
ls -l /usr/local/mysql

# change permission
sudo chmod -R g+rwx /usr/local/var/mysql

https://stackoverflow.com/questions/21470193/mysql-server-start-issues-on-mavericks

你可能感兴趣的:(SQL)