mysql使用者本地登入localhost和127.0.0.1區別
今天某個透過ansible給某個機器安裝上mysql_exporter,然後無法採集到mysql的資訊,登入到mysql伺服器,發現是自動建立的zabbix_monitor@127.0.0.1賬號,無法登入,然後做了如下的測試:
mysql -uzabbix_monitor -p'**********' -h127.0.0.1 ------無法登入
mysql -uzabbix_monitor -p'******' -S /tmp1/mysql.sock-----無法登入
mysql -uroot -p'1234' ------可以登入
root可以登入上,我當時就認為埠是預設的3306,然後就沒從這方面想,最後確認是埠3307的問題!
一、MySQL本地登入方式:
方式1:指定ip+埠
mysql -uzabbix_monitor -p'rwg*******Y!' -h127.0.0.1 -P3307
方式2:透過sock
mysql -uzabbix_monitor -p'rwg*******Y!' -S /tmp1/mysql.sock
二、localhost和127.0.0.1在msyql5.7中:
mysql只有zabbix_monitor@localhost這類的賬號可以使用sock檔案登入,zabbix_monitor@127.0.0.1這類的不可以透過本地sock檔案登入;
結論1:針對zabbix_monitor@127.0.0.1這個賬號,本地只可以可以透過 方式1登入
方式1登入正常:
[root@localhost ~]# mysql -uzabbix_monitor -p'**********' -h127.0.0.1 -P3307
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 596
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
透過方式2報錯:
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| socket | /tmp/mysql.sock |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> exit
Bye
[root@localhost ~]# mysql -uzabbix_monitor -p'**********' -S /tmp/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'zabbix_monitor'@'localhost' (using password: YES)
You have new mail in /var/spool/mail/root
結論2:針對liuwenhe@localhost這類的賬號,可以透過sock檔案的方式登入,也可以透過ip+port的方式登入
mysql> select user ,host from mysql.user where user='liuwenhe';
+----------+-----------+
| user | host |
+----------+-----------+
| liuwenhe | localhost |
+----------+-----------+
1 row in set (0.00 sec)
方式1可以登入:
[root@testdb1:/root]# mysql -uliuwenhe -p'*********' -hlocalhost -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 73
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
方式2 可以登入:
[root@testdb1:/root]# mysql -uliuwenhe -p'********' -S /data/mysql/data/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 76
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
注意:如果你在配置檔案中[client]下配置了socket,那麼它會去你指定的路徑下找,如果你沒有配置,它預設會找/tmp/mysql.sock這個sock檔案;
如果你的sock檔案不在預設的/tmp下,並且配置檔案也沒有指定真實的sock路徑;那麼此時登入就會報錯:
[root@testdb1:/root]# mysql -uliuwenhe -p'*********'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
如果你的sock檔案不在預設的/tmp下,你可以在配置檔案配置好sock檔案的真實路徑!如下所示:
cat /etc/my.cnf
[client]
port = 3307
socket = /data/mysql/data/mysql.sock
然後如下所示就可以登入了:
[root@testdb1:/root]# mysql -uliuwenhe -p'**********'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 82
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
總結:
1、針對liuwenhe@localhost這類的賬號,可以透過sock檔案的方式登入,也可以透過ip+port的方式登入;
2、針對zabbix_monitor@127.0.0.1這個賬號,本地只可以可以透過 方式1sock檔案登入;
3、mysql -uroot -p可以登入,不能說明其埠是3306,因為它可能是透過本地sock檔案登入的;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29654823/viewspace-2931235/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL主機127.0.0.1與localhost區別MySql127.0.0.1localhost
- localhost與127.0.0.1的區別localhost127.0.0.1
- mysql localhost登入和tcp/ip登入MySqllocalhostTCP
- 徹底明白ip地址,區分localhost、127.0.0.1和0.0.0.0localhost127.0.0.1
- 本地開發 localhost連結資料庫比127.0.0.1慢localhost資料庫127.0.0.1
- bind 127.0.0.1 ::1 和 bind 127.0.0.1 有什麼區別127.0.0.1
- Call From localhost.localdomain/127.0.0.1 to localhost:40984localhostAI127.0.0.1
- [ASP.NET]關於DOT NET的IIS配置LocalHost訪問和127.0.0.1訪問的區別ASP.NETlocalhost127.0.0.1
- MYSQL建立使用者後本地無法登入的原因MySql
- VSFTPD 本地使用者登入。FTP
- sql server 登入名和使用者名稱的區別和聯絡SQLServer
- vsftp本地使用者不能登入FTP
- Cookie和Session的區別,Koa2+Mysql+Redis實現登入邏輯CookieSessionMySqlRedis
- oracle12c CDB中共同使用者和本地使用者區別Oracle
- oracle本地登入Oracle
- 對SSO單點登入和OAuth2.0的區別和理解OAuth
- 本地連線時,通過localhost不能登陸到指定的埠localhost
- MySQL 登入資料庫報錯'ERROR 1045 (28000): Access denied for user'..'@'localhost''MySql資料庫Errorlocalhost
- MYSQL和SQL的區別MySql
- mysql中!=和is not的區別MySql
- mysql中“ ‘ “和 “ ` “的區別MySql
- MySQL和Oracle的區別MySqlOracle
- bind-address如果是127.0.0.1,mysql只接受localhost,不接受遠端連線127.0.0.1MySqllocalhost
- mysql密碼和登入問題MySql密碼
- MySQL中CHAR和VARCHAR區別MySql
- 【轉】mysql 和 redis的區別MySqlRedis
- MS SQL Server和MySQL區別ServerMySql
- win10怎麼改本地登入 win10如何改本地賬戶登入Win10
- 破解本地 mysql 使用者名稱和密碼(轉)MySql密碼
- 本地事務和分散式事務的區別分散式
- Oracle XE 自動以本地最高使用者登入例項 for windows XPOracleWindows
- Linux+Oracle10g RAC設定hosts中的127.0.0.1 localhostLinuxOracle127.0.0.1localhost
- SQLserver-MySQL的區別和用法ServerMySql
- mongodb和mysql有什麼區別MongoDBMySql
- Oracle 和 mysql的9點區別OracleMySql
- Mysql 中 MyISAM 和 InnoDB 的區別MySql
- 談談mysql和redis的區別MySqlRedis
- mysql 中set和enum的區別MySql