mysql 忘记密码重置密码和修改密码

Linux下MySQL重置密码

Linux下重置密码的操作与Windows下类似。

停止MySQL服务

[root@www ~]# /etc/init.d/mysql stop

以安全模式启动MySQL

[root@www ~]# /usr/local/mysql/bin/mysqld_safe –skip-grant-tables &

登录MySQL

[root@www ~]# mysql -u root -p

mysql> use mysql;
mysql> update user set password=password(“123456″) where user=”root”;
mysql> flush privileges;

启动MySQL服务

[root@www ~]# /etc/init.d/mysql start
注意了,MySQL5.7之后,重置root密码SQL(感谢刘韦声回复):

update mysql.user set authentication_string=password('123456') where user='root';

创建用户

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON myapp.* TO 'username'@'localhost';
FLUSH PRIVILEGES