linux 安装完mysql 密码重置

If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset themysql database password from the command line in either Linux or macOS Sierra and OSX as long as you know the root user password of the box you are on, this is for MySQL 5.7 onwards:

Stop MySQL

sudo /usr/local/mysql/support-files/mysql.server stop

Start it in safe mode:

sudo mysqld_safe --skip-grant-tables

This will be an ongoing command until the process is finished so open another shell/terminal window, and log in without a password as root:

mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.

\q

Start MySQL

sudo /usr/local/mysql/support-files/mysql.server start

Thats it, now your root password will be updated.

posted @ 2016-10-20 16:01  崔国亮  阅读(267)  评论(0编辑  收藏  举报