本地連線時,通過localhost不能登陸到指定的埠
本地連線時,通過localhost不能登陸到指定的埠
朋友說他的一臺伺服器上,裝了多個mysql,用了不同的埠,通過localhost的方式指定埠時,連上的還是3306的埠
mysql -uroot -hlocalhost -P3307 -p
這樣連的是 3306的庫。
但是通過
mysql -uroot -h127.0.0.1 -P3307 -p
連到的是 3307的庫。
這是為什麼
我在我本地一臺伺服器上建了兩個例項, 3306和3308
mysql -uroot -h127.0.0.1 -P3308
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.24 Source distribution
Copyright (c) 2000, 2011, 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 user,host from mysql.user;
+------+------------+
| user | host |
+------+------------+
| root | 10-4-1-104 |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+------------+
mysql -uroot --host=localhost -P3308
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
這種方式,直接就連不上。
檢視了文件 5.6 p264
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from
what you expect compared to other network-based programs. For connections to localhost, MySQL
programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port
or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the
local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of
the local server. You can also specify the connection protocol explicitly, even for localhost, by using the
--protocol=TCP option.
當使用localhost的時候,會試著用socket檔案,雖然你指定了埠。
指定--protocol=TCP 可以避免這種情況。
在我的環境中:
mysql -uroot -hlocalhost -P3308 --protocol=TCP
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.24 Source distribution
Copyright (c) 2000, 2011, 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> show variables like '%port%'
-> ;
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_support_xa | ON |
| large_files_support | ON |
| port | 3308 |
| report_host | |
| report_password | |
| report_port | 3308 |
| report_user | |
+---------------------+-------+
告訴朋友,讓他加上 --protocol=TCP 之後,也可以正常的連線到想連線的埠
總結:在本地使用localhost登陸庫時,如果需要連線到別的埠需要 加上--protocol=TCP
轉載請註明源出處
QQ 273002188 歡迎一起學習
QQ 群 236941212
QQ 273002188 歡迎一起學習
QQ 群 236941212
oracle,mysql,mongo 相互交流
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25099483/viewspace-1821035/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 解決Mysql中只能通過localhost登陸不能通過ip登陸的問題MySqllocalhost
- 通過session模擬登陸Session
- 解決tomcat伺服器下,只能通過localhost,而不能通過127.0.0.1或者本地ip地址訪問的問題Tomcat伺服器localhost127.0.0.1
- java本地連線遠端Hbase可是返回zookeeper的地址是localhostJavalocalhost
- ssh只能遠端登陸到普通使用者,不能以root遠端登陸
- nginx 怎麼通過域名訪問8080埠(指定埠)Nginx
- Oracle 11G RAC 本地時間和通過listener連線時間不相同的問題Oracle
- 轉:linux 下mysql指定連線的埠 或socketLinuxMySql
- 通過論壇實現登陸的程式碼
- 如何通過隧道將本地主機連線到公共網際網路上 - Vlad Mihalcea
- 網頁訪問Localhost本地埠的趕快升級啦網頁localhost
- 怎樣通過驅動程式連線到access
- 通過ODBC連線windows下SQLServer到UNIX oracleWindowsSQLServerOracle
- 使用串列埠連線到Linux串列埠Linux
- 樹莓派已經通過網路連線通過串列埠通訊在串列埠除錯小助手列印與操作樹莓派串列埠除錯
- grid監聽故障,本地地址不能連線
- 連線PostgreSQL時,如何指定引數SQL
- 求助:關於通過電腦控制安卓手機 連線指定 WIFI安卓WiFi
- mysql 通過IP連線MySql
- trace 檔案產生過多,使用者不能登陸
- 通過本地直接連線linux伺服器的mysql資料庫Linux伺服器MySql資料庫
- RMAN登陸及連線target資料庫的步驟方法資料庫
- fedora 17的root不能圖形介面登陸
- MYSQL 連線登入過程分析MySql
- 11gR2不能在client段通過scanip連線的解決辦法client
- Laravel 通過 ODBC 連線 VerticaLaravel
- 通過跳板機連線MySQLMySql
- git 登陸時注意Git
- MySQL login-path 本地快捷登陸MySql
- pymssql登陸本地sql server 伺服器SQLServer伺服器
- EOSCleos連線到非預設主機/埠
- [提問交流]本地正常 上傳到伺服器後無法登陸伺服器
- [Oracle-> MySQL] Oracle通過dblink連線MySQL--Oracle 19c連線到MySQL 5.7OracleMySql
- 使用telnet測試指定埠的連通性
- ssh設定使用者從指定的IP登陸
- oracle連線SQLserver--通過ODBCOracleSQLServer
- 通過驅動建立與MySQL的連線MySql
- mysql使用者本地登入localhost和127.0.0.1區別MySqllocalhost127.0.0.1