mysql modify secret

1 Stop MySQL:

$ sudo service mysql stop
or
$ sudo /usr/local/mysql/support-files/mysql.server stop
or
$ /etc/init.d/mysql stop

2 Start it in safe mode:
to do first

$ sudo mkdir -p /var/run/mysqld
$ sudo chown mysql:mysql /var/run/mysqld

then

$ sudo mysqld_safe --skip-grant-tables 

This will be an ongoing command until the process is finished, after the secret is changed, ctrl+z to stop it.

3 Open another shell/terminal window, log in without a password:

$ mysql -u root
mysql>use mysql;

MySQL5.6 and under:

mysql> UPDATE user SET Password=PASSWORD('password'),plugin='mysql_native_password' WHERE User='root';

MySQL 5.7 and over:

mysql> update user set authentication_string=password('password'),plugin='mysql_native_password' where user='root'; 

now to stop the mysql_safe process

4 Start MySQL:

sudo service mysql start

Your new password is 'password'.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容