免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3776 | 回复: 1

[Mail] mysql的root用户被删除后,重新建立了一个,然后赋予权限报错 [复制链接]

论坛徽章:
0
发表于 2010-08-27 22:46 |显示全部楼层
整个过程如下
一、root被误删除后,无法再登录数据库,用如下方法恢复
处理
[root@mail bin]# ./mysqld_safe --skip-grant-tables --user=mysql &      跳过权限表启动
[1] 16753
[root@mail bin]# Starting mysqld daemon with databases from /usr/local/mysql/var

[root@mail bin]# ps -ef|grep mysql
root     16753 16366  0 05:25 pts/2    00:00:00 /bin/sh ./mysqld_safe --skip-grant-tables --user=mysql
mysql    16782 16753  0 05:25 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql --pid-file=/usr/local/mysql/var/mail.pid --skip-external-locking --port=3306 --socket=/tmp/mysql.sock --skip-grant-tables
root     16794 16366  0 05:25 pts/2    00:00:00 grep mysql
[root@mail bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.54-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)

mysql> insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
Query OK, 1 row affected (0.00 sec)
(这时可能会提示某字段如ssl_cipher无默认值, 只要加上,ssl_cipher=''; 其字段如有提示依次添加就OK了)


mysql> update user set Host='localhost',select_priv='y', insert_priv='y',update_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';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> quit
Bye
[root@mail bin]# service mysqld stop
Shutting down MySQLSTOPPING server from pid file /usr/local/mysql/var/mail.pid
100827 05:28:43  mysqld ended

                                                           [  纭?畾  ]
[1]+  Done                    ./mysqld_safe --skip-grant-tables --user=mysql
[root@mail bin]# service mysqld start                                    正常启动
Starting MySQL                                             [  纭?畾  ]
[root@mail bin]# ./mysql -u root                                         这个时候已经不需要密码可以进入了
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.54-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql;
Database changed
mysql>  update user set password=password('123456') where user='root';        设置密码
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


测试
[root@mail bin]# ./mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mail bin]# ./mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.54-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

二、然后发现如下问题
mysql> GRANT all privileges on extmail.* TO webman@localhost IDENTIFIED BY 'webman';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'extmail'
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql>


三、网上找资料操作如下,发现还是不行
[root@mail bin]# mysqld_safe --user=mysql --skip-grant-tables &
[1] 17163
[root@mail bin]# Starting mysqld daemon with databases from /usr/local/mysql/var

[root@mail bin]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.54-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Database changed
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

[root@mail bin]# service mysqld restart
Shutting down MySQLSTOPPING server from pid file /usr/local/mysql/var/mail.pid
100827 06:28:21  mysqld ended

                                                           [  纭?畾  ]
Starting MySQL                                             [  纭?畾  ]
[1]+  Done                    mysqld_safe --user=mysql --skip-grant-tables
[root@mail bin]# mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.54-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> GRANT all privileges on extmail.* TO webman@localhost IDENTIFIED BY 'webman';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'extmail'
mysql> GRANT all privileges on extmail.* TO webman@localhost IDENTIFIED BY 'webman';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'extmail'
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


望高手解决呀!!!!!!!!!!

论坛徽章:
0
发表于 2010-08-29 21:36 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP