天天看點

mysqld --skip-grant-tables

mysqld的--skip-grant-tables選項

這個選項會導緻不使用權限系統來啟動伺服器,它将讓任何使用者可以通路伺服器并且不受限制的通路所有資料庫。在不使用授權表啟動伺服器後可以通過shell來執行mysqladmin flush-privileges或mysqladmin reload指令或者在連接配接到伺服器後執行flush privileges語句來讓正在運作的伺服器再次使用授權表。

使用--skip-grant-tables選項啟動伺服器

[root@localhost mysql]# service mysqld stop

Shutting down MySQL. SUCCESS!

[root@localhost mysql]# service mysqld start --skip-grant-tables

Starting MySQL.. SUCCESS!

現在就可以不使用使用者和密碼就可以登入伺服器

[mysql@localhost ~]$ mysql

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 2

Server version: 5.7.26-log Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

  1. Other names may be trademarks of their respective

    owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

現在可以執行mysqladin flush-privileges指令讓正在運作的伺服器再次使用授權表

[mysql@localhost ~]$ mysqladmin flush-privileges

現在不使用使用者和密碼就不能登入伺服器了,必須使用使用者和密碼才能登入了

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[mysql@localhost ~]$ mysql -uroot -pabcd mysql

mysql: [Warning] Using a password on the command line interface can be insecure.

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Your MySQL connection id is 5

再次使用--skip-grant-tables選項啟動伺服器

Shutting down MySQL.. SUCCESS!

現在可以執行mysqladin reload指令讓正在運作的伺服器再次使用授權表

mysql@localhost ~]$ mysqladmin reload

現在可以執行flush privileges語句讓正在運作的伺服器再次使用授權表

mysql> flush privileges;

Query OK, 0 rows affected (0.12 sec)

--skip-grant-tables選項也可以在選項檔案my.cnf中進行設定。這個選項還會導緻伺服器在啟動過程中禁止加載使用者定義函數(udf),排程事件和安裝插件語句中安裝的插件。為了以任何方式來加載插件,使用--plugin-load選項。--skip-grant-tables選項也會導緻disabled_storage_engines系統變量失效。

flush privileges語句可以在伺服器啟動後通過執行其它操作來隐式執行。例如在更新過程中mysql_upgrade程式就會重新整理權限。