linux下mysql修改密码

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using passwor:yes)
一般这个错误是由密码错误引起,解决的办法自然就是重置密码
你可以尝试以下操作来重置你的密码

1、关闭mysql(三种选一种)

1、使用 service 启动:service mysql stop
2、使用 mysqld 脚本启动:/etc/inint.d/mysql stop
3、mysqladmin shutdown

2、查看mysql状态 任意路径输入:mysql

linux下mysql修改密码

3、vim /etc/my.cnf

linux下mysql修改密码
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

4、启动mysql(选一种)

1、使用 service 启动:service mysql restart
2、使用 mysqld 脚本启动:/etc/inint.d/mysql restart

5、进入mysql

mysql -u root -p(mysql)
出现密码输入时,不用输入直接按回车,就可以不用密码就能登录

linux下mysql修改密码

6、进入mysql 自带的 mysql数据库user表修改root密码

linux下mysql修改密码

7、执行命令 update user set password=password(“密码”) where user=“用户”

linux下mysql修改密码

8、如果报错:ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’

原因: 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

update user set authentication_string=password(“密码”) where user=”用户名”;

9、密码修改完毕

编辑/etc/my.cnf,将上面添加的内容去掉(skip-grant-tables)
重启MySQL
使用新密码登录即可

相关文章: