mysql中root使用者誤刪的處理辦法
在mysql安裝後,清理無用的許可權,使用如下語句:
delete from user where (user,host) not in (select 'root','localhost');
由於上述語句寫錯為:
delete from user where (user,host) not in (select 'root','local');導致root使用者被刪除。
補救措施:
1、由於沒有root使用者,無法使用mysqladmin關閉mysql,所以在作業系統層直接殺掉mysql程式:
[root@linfytest3 ~]# ps -ef|grep mysql
root 29356 1 0 15:55 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf
mysql 30506 29356 8 17:00 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql3307/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql3307 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql3307/linfytest3.err --pid-file=/var/lib/mysql3307/linfytest3.pid --socket=/tmp/mysql3307.sock --port=3307
root 30531 29955 0 17:00 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# kill -9 29356
[root@linfytest3 ~]# ps -ef|grep mysql
mysql 30506 1 2 17:00 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql3307/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql3307 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql3307/linfytest3.err --pid-file=/var/lib/mysql3307/linfytest3.pid --socket=/tmp/mysql3307.sock --port=3307
root 30534 29955 0 17:00 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# kill -9 30506
[root@linfytest3 ~]# ps -ef|grep mysql
root 30555 29955 0 17:01 pts/3 00:00:00 grep mysql
注意,先殺主程式29356,再殺子程式30506,如果先殺子程式30506,那麼mysql程式會自動重啟。
2、使用引數--skip-grant-tables啟動資料庫,啟動資料庫時不進行許可權驗證
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf --skip-grant-tables &
[1] 30677
[root@linfytest3 ~]# 150928 17:04:09 mysqld_safe Logging to '/var/lib/mysql3307/linfytest3.err'.
150928 17:04:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3307
3、不用root使用者也可以登入mysql伺服器了
[root@linfytest3 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3307.sock
4、使用SQL語句新增root使用者
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
Query OK, 1 row affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> UPDATE user SET 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',Alter_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',authentication_string='' WHERE User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from users;
ERROR 1146 (42S02): Table 'mysql.users' doesn't exist
mysql> select host,user,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
+-----------+------+----------+
1 row in set (0.00 sec)
5、修改root密碼:
[root@linfytest3 ~]# mysqladmin -S /tmp/mysql3307.sock password 111111
Warning: Using a password on the command line interface can be insecure.
mysqladmin:
You cannot use 'password' command as mysqld runs
with grant tables disabled (was started with --skip-grant-tables).
Use: "mysqladmin flush-privileges password '*'" instead
提示:使用--skip-grant-tables引數啟動資料庫,不允許修改root密碼
6、重啟mysql
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqladmin -uroot -S /tmp/mysql3307.sock shutdown
150928 17:14:39 mysqld_safe mysqld from pid file /var/lib/mysql3307/linfytest3.pid ended
[1]+ Done /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf --skip-grant-tables
[root@linfytest3 ~]# ps -ef|grep mysql
root 30931 29955 0 17:14 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf &
[1] 30934
[root@linfytest3 ~]# 150928 17:15:08 mysqld_safe Logging to '/var/lib/mysql3307/linfytest3.err'.
150928 17:15:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3307
7、再次修改root密碼:
[root@linfytest3 ~]# mysqladmin -S /tmp/mysql3307.sock password 111111
Warning: Using a password on the command line interface can be insecure.
修改成功!
修改密碼的第二種方法:
使用SQL語句修改:
mysql> update user set password=password('111111') where user='root';
Query OK, 0 rows affected (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *FD571203974BA9AFE270FE62151AE967ECA5E0AA |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
delete from user where (user,host) not in (select 'root','localhost');
由於上述語句寫錯為:
delete from user where (user,host) not in (select 'root','local');導致root使用者被刪除。
補救措施:
1、由於沒有root使用者,無法使用mysqladmin關閉mysql,所以在作業系統層直接殺掉mysql程式:
[root@linfytest3 ~]# ps -ef|grep mysql
root 29356 1 0 15:55 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf
mysql 30506 29356 8 17:00 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql3307/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql3307 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql3307/linfytest3.err --pid-file=/var/lib/mysql3307/linfytest3.pid --socket=/tmp/mysql3307.sock --port=3307
root 30531 29955 0 17:00 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# kill -9 29356
[root@linfytest3 ~]# ps -ef|grep mysql
mysql 30506 1 2 17:00 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql3307/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql3307 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql3307/linfytest3.err --pid-file=/var/lib/mysql3307/linfytest3.pid --socket=/tmp/mysql3307.sock --port=3307
root 30534 29955 0 17:00 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# kill -9 30506
[root@linfytest3 ~]# ps -ef|grep mysql
root 30555 29955 0 17:01 pts/3 00:00:00 grep mysql
注意,先殺主程式29356,再殺子程式30506,如果先殺子程式30506,那麼mysql程式會自動重啟。
2、使用引數--skip-grant-tables啟動資料庫,啟動資料庫時不進行許可權驗證
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf --skip-grant-tables &
[1] 30677
[root@linfytest3 ~]# 150928 17:04:09 mysqld_safe Logging to '/var/lib/mysql3307/linfytest3.err'.
150928 17:04:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3307
3、不用root使用者也可以登入mysql伺服器了
[root@linfytest3 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3307.sock
4、使用SQL語句新增root使用者
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
Query OK, 1 row affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> UPDATE user SET 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',Alter_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',authentication_string='' WHERE User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from users;
ERROR 1146 (42S02): Table 'mysql.users' doesn't exist
mysql> select host,user,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
+-----------+------+----------+
1 row in set (0.00 sec)
5、修改root密碼:
[root@linfytest3 ~]# mysqladmin -S /tmp/mysql3307.sock password 111111
Warning: Using a password on the command line interface can be insecure.
mysqladmin:
You cannot use 'password' command as mysqld runs
with grant tables disabled (was started with --skip-grant-tables).
Use: "mysqladmin flush-privileges password '*'" instead
提示:使用--skip-grant-tables引數啟動資料庫,不允許修改root密碼
6、重啟mysql
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqladmin -uroot -S /tmp/mysql3307.sock shutdown
150928 17:14:39 mysqld_safe mysqld from pid file /var/lib/mysql3307/linfytest3.pid ended
[1]+ Done /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf --skip-grant-tables
[root@linfytest3 ~]# ps -ef|grep mysql
root 30931 29955 0 17:14 pts/3 00:00:00 grep mysql
[root@linfytest3 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/var/lib/mysql3307/my.cnf &
[1] 30934
[root@linfytest3 ~]# 150928 17:15:08 mysqld_safe Logging to '/var/lib/mysql3307/linfytest3.err'.
150928 17:15:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3307
7、再次修改root密碼:
[root@linfytest3 ~]# mysqladmin -S /tmp/mysql3307.sock password 111111
Warning: Using a password on the command line interface can be insecure.
修改成功!
修改密碼的第二種方法:
使用SQL語句修改:
mysql> update user set password=password('111111') where user='root';
Query OK, 0 rows affected (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *FD571203974BA9AFE270FE62151AE967ECA5E0AA |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/543979/viewspace-1811280/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【問題處理】MySQL忘記root密碼的處理辦法MySql密碼
- mysql的root使用者無法給普通使用者授權問題處理MySql
- MySQL誤刪root使用者恢復一例MySql
- mysql誤刪root使用者或者忘記root密碼解決方法MySql密碼
- mysql 8.0忘記root使用者密碼處理MySql密碼
- mysql中的root密碼忘記的解決辦法MySql密碼
- 遭遇另類無法刪除病毒的處理辦法(轉)
- ORA-19693錯誤後的處理辦法
- 關於root(其他)使用者拒絕登陸mysql的處理方法MySql
- oracle 誤刪除的處理方法Oracle
- 【undo】undo 意外刪除處理辦法(非歸檔)
- MySQL忘記root密碼後的處理MySql密碼
- mysql丟失root密碼的解決辦法MySql密碼
- 解決非root使用者使用docker的辦法Docker
- 無法刪除pod的處理
- 誤刪除dual表的解決辦法
- MySQL 處理插入過程中的主鍵唯一鍵重複值辦法MySql
- MySQL 忘記root密碼解決辦法MySql密碼
- ORA-00600: [kcratr1_lastbwr]錯誤的處理辦法AST
- PowerShell的異常處理辦法
- mysql 4.1.7忘記資料庫密碼的處理辦法MySql資料庫密碼
- root使用者執行root.sh失敗怎麼處理
- MySQL5.7忘記root密碼處理MySql密碼
- MySql5.5忘記root密碼的解決辦法MySql密碼
- Oracle 10g 中誤刪除(drop)表的恢復處理Oracle 10g
- oracle rac修改ip的處理辦法Oracle
- oracle 表碎片太多的處理辦法Oracle
- QQ病毒的系列處理辦法(轉)
- 被誤刪的檔案正確處理方法,快速找回誤刪的檔案
- CentOS7忘記mysql的root密碼_處理方法.CentOSMySql密碼
- access資料庫80040e09錯誤處理辦法資料庫
- 【問題處理】使用者無法順利刪除問題處理一則-ORA-00604和ORA-00942錯誤
- Restful API 中的錯誤處理RESTAPI
- 【譯】RxJava 中的錯誤處理RxJava
- grpc中的錯誤處理RPC
- 刪除mysql relay-log 的解決辦法MySql
- MySQL中的事務處理MySql
- 磁碟IO過高時的處理辦法