Situation One:
To modify the MySQL admin password in the case of a known password:
mysqladmin-uroot-p123 Password 123456
Situation Two:
In the case of forgetting the MySQL login password, empty or log in to the MySQL admin password:
1. #停止mysqld服务
/etc/init.d/mysqld stop
2. #使用mysqld_safe启动服务器. Starting MySQL will allow anyone to access the MySQL server with a root user and a blank password
#允许本和网络远程登录
/application/mysql/bin/mysqld_safe--skip-grant-tables&
#不允许网络远程登录(recommended)
/application/mysql/bin/mysqld_safe--skip-grant-tables--skip-networking &
3. #使用mysql语句直接登录, no password required here
Mysql
4#. Modifying the password using the MySQL statement, modifying the authorization table
Version 5.6:
Mysql>use MySQL; Update Mysql.user set Password=password (' 123 ') where user= ' root ' and host= ' localhost '; #把root用户更新密码为 123456
Exit #退出
Version 5.7: Password field changed to Authentication_strings
Update Mysql.user set Authentication_string=password (' 123 ') where user= ' root ' and host= ' localhost ';
5. #然后重启mysql so that the root password for MySQL is modified
/etc/init.d/mysqld restart
What if I forgot my MySQL admin password?