用戶管理模塊之mysql.user
阿新 • • 發佈:2017-07-15
用戶 ddc 端口 ner target 默認 spl local resolve
不使用-h參數來指定登錄host,默認會連接localhost,僅當mysql.user表中有一條對應的localhost訪問授權(username@%不對任何主機做限制也不行)時登錄才成功,否則登錄會被拒絕。
虛擬機VMUest上安裝兩個MySQL實例,兩個實例搭建了Master(端口3306)-Slave(端口3307),主從數據完全一致。
mysql> select Host,User,Password from mysql.user; +-----------------------+--------+-------------------------------------------+View Code| Host | User | Password | +-----------------------+--------+-------------------------------------------+ | localhost | root | *6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119 | | localhost.localdomain | root | || 127.0.0.1 | root | | | ::1 | root | | | localhost | | | | localhost.localdomain | | || % | mydba | *80BF8C1F4008F25267DB194E29D2E8BC20C836ED | | % | backup | *975B2CD4FF9AE554FE8AD33168FBFC326D2021DD | | 192.168.85.% | repl | *A424E797037BF97C19A2E88CF7891C5C2038C039 | +-----------------------+--------+-------------------------------------------+ 9 rows in set
使用root用戶登錄
#不指定-h參數,默認就會走localhost [[email protected] ~]$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec) mysql> exit Bye [[email protected] ~]$ mysql -uroot -p -P3307 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec) mysql> exit Bye #指定-h+ip參考,同時指定-P端口 [[email protected] ~]$ mysql -uroot -p -h127.0.0.1 -P3306 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec) mysql> exit Bye [[email protected] ~]$ mysql -uroot -p -h127.0.0.1 -P3307 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3307 | +--------+ 1 row in set (0.00 sec) mysql> exit Bye #指定-h+localhost參考,同時指定-P端口 [[email protected] ~]$ mysql -uroot -p -hlocalhost -P3307 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec) mysql> exit Bye [[email protected] ~]$View Code
從上面的結果可以看出只有在指定-h+ip,同時指定-P端口的情況下,才能連接到指定的端口中。
註意:[email protected]空(即不需要輸入密碼),但實際登錄過程需要輸入密碼。這是受skip_name_resolve參數影響
mysql> show variables like ‘%skip_name_resolve%‘; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | skip_name_resolve | OFF | +-------------------+-------+ 1 row in setView Code
該參數的值為OFF,[email protected]@‘localhost‘登錄,[email protected]啟skip_name_resolve參數(配置文件my.cnf中添加skip_name_resolve=1),然後使用空密碼登錄。
mysql.user表中第5條記錄Host=‘localhost‘,User和Password字段為空,也就是localhost可以不指定用戶、密碼直接登錄
[[email protected] ~]$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 26 Server version: 5.6.35-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select @@port; +--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec) mysql>View Code
還是有一些小細節需要註意。引用iVictor一段話:[email protected][email protected],如果開啟skip_name_resolve參數,[email protected][email protected],如果沒有開啟該參數,[email protected]@‘localhost‘登錄,[email protected]%‘定義的密碼並不適用。
用戶管理模塊之mysql.user