mysql5.7误删管理员root账户ERROR1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

1)停止数据库
kill Mysql进程 关闭数据库服务
.停止数据库,并在mysql配置文件my.cnf中添加skip-grant-tables参数到[mysqld]配置块中

2)在加上 --skip-grant-tables启动mysql 进程加粗样式
其中–skip-grant-tables意思是启动MySQL 服务的时候跳过权限表认证。
启动后,连接到MySQL 的root 将不需要口令
cd /mysqldata/mysql/bin
./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --skip-grant-tables&
3)用空密码的root 用户连接到MySQL,并且更改root 口令
mysql -uroot -p
use mysql;

insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
 
update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y', Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';
 
update user set authentication_string=password('123456') where user='root';

刷新 退出mysql
flush privileges;
quit
注释掉skip-grant-tables参数,重启数据库
修改 关机重启

MySQL5.7使用错误解决:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)【取消或重设root密码】
解决方法:

最简单方法:

⑴打开mysql中的my.ini(如果没有就将my-default.ini复制一份,并修改为my.ini);

⑵在[mysqld]下面空白行直接添加skip-grant-tables;

⑶重启mysql,在cmd页面输入mysql,按回车键即可。

注:这会使你的mysql无法设置密码,但对个人使用而言这岂不是更省了一步!

重设root密码:

⑴停止mysql服务:net stop mysql

⑵输入:mysqld --skip-grant-tables

⑶重新打开一个cmd窗口,输入:mysql -u root

⑷登录成功后输入:update mysql.user set authentication_string=password(‘你的密码’) where user=‘root’ and host=‘localhost’;

【经验错误:ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’,原因:mysql数据库下已经没有password这个字段了,password字段改成了authentication_string】

⑸让设置的密码生效:flush privileges;

⑹输入\q退出mysql。

注:

①如果直接关掉第一个cmd窗口后,要用资源管理器把mysql进程关掉,否则设置前的mysql依然在运行着;

②MySQL5.7 设置的密码建议至少包含一个大写字母、一个小写字母、一个特殊符号、一个数字,密码长度至少为8个字符;

③登录mysql的输入方式为:mysql -u root -p,然后输入你的密码就OK啦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值