解决误删mysql.user中user:root host:localhost那一行

  • Post author:
  • Post category:mysql



导致从本地输入


Mysql  -uroot -p 显示:ERROR 1045 (28000): Access denied for user root@localhost(也就是从本地不能登录以root身份登录)


首先我的系统是


ubuntu14.04 64位,重建后用户和密码都是root


1、Service  mysql stop(停止mysql服务)


2、mysqld_safe –user=mysql –skip-grant-tables –skip-networking (–skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。


–skip-networking :跳过TCP/IP协议,




3、mysql -u root mysql


4、insert into mysql.user (host, user, password,ssl_cipher,x509_issuer,x509_subject) values (‘localhost’, ‘root’, password(‘root’),”,”,”);


5、flush privileges;


6、 grant all privileges on *.* to ‘root’@’localhost’ identified by ‘root’;如果报错试试执行这句话





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’;




7、flush privileges;


8、service  mysql start


这样在linux界面下输入mysql -uroot -p 就可以登陆了







版权声明:本文为u012802020原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。