1.关闭数据:
/etc/init.d/mysql stop
2.启动数据库:
mysqld_safe --skip-grant-tables &
3.登录数据库,插入root用户并设置权限:
mysql //无密码登录
mysql> use mysql
mysql> insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
mysql> flush privileges;
4.给root用户添加权限:
mysql> 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',Event_priv='y',Trigger_priv='y',Create_tablespace_priv='y' where user='root' and host='localhost';commit;
mysql> quit;
5.重启数据:
/etc/init.d/mysql restart
6.登录数据库(无密码登录):
mysql

7.设置root密码:
update mysql.user set password=password('newpassword') where user='root'

注把原有root账户改为远程登录:
update user set host='192.168.30.130' where user='root' and host='%';