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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 徹底明白ip地址,區分localhost、127.0.0.1和0.0.0.0localhost127.0.0.1
- 127.0.0.0和localhost區別localhost
- bind 127.0.0.1 ::1 和 bind 127.0.0.1 有什麼區別127.0.0.1
- ip 地址 127.0.0.1 和 0.0.0.0 的區別127.0.0.1
- [ASP.NET]關於DOT NET的IIS配置LocalHost訪問和127.0.0.1訪問的區別ASP.NETlocalhost127.0.0.1
- 127.0.0.1和0.0.0.0的區別是什麼?127.0.0.1
- Cookie和Session的區別,Koa2+Mysql+Redis實現登入邏輯CookieSessionMySqlRedis
- bind-address如果是127.0.0.1,mysql只接受localhost,不接受遠端連線127.0.0.1MySqllocalhost
- 對SSO單點登入和OAuth2.0的區別和理解OAuth
- Oracle和MySQL的區別OracleMySql
- MYSQL和SQL的區別MySql
- mysql中“ ‘ “和 “ ` “的區別MySql
- MySQL和Oracle的區別MySqlOracle
- mysql中!=和is not的區別MySql
- MySQL中CHAR和VARCHAR區別MySql
- MySQL login-path 本地快捷登陸MySql
- mysql alter modify 和 change的區別MySql
- MySQL中datetime和timestamp的區別MySql
- mongodb和mysql有什麼區別MongoDBMySql
- MySQL之Where和Having的區別MySql
- 談談mysql和redis的區別MySqlRedis
- Mysql 中 MyISAM 和 InnoDB 的區別MySql
- SQLserver-MySQL的區別和用法ServerMySql
- Oracle 和 mysql的9點區別OracleMySql
- 本地事務和分散式事務的區別分散式
- win10怎麼改本地登入 win10如何改本地賬戶登入Win10
- mybatis入門程式:刪除、更新使用者&&hibernate和mybatis的區別MyBatis
- phpstudy配置本地ssl證照,訪問https://127.0.0.1PHPHTTP127.0.0.1
- Mysql匯入本地檔案MySql
- Tomcat 中 catalina.out、catalina.log、localhost.log 和 access_log 的區別Tomcatlocalhost
- Linux中登入mysqlLinuxMySql
- MySQL安全登入策略MySql
- mysql怎麼登入MySql
- mysql主從和主備的區別MySql
- MySQL中REPLACE INTO和INSERT INTO的區別分析MySql
- 使用者態和核心態的區別
- [20211108]sqlplus 本地登入緩慢.txtSQL
- linux 免登入以及配置別名登入Linux