本地连接时,通过localhost不能登陆到指定的端口
生活随笔
收集整理的這篇文章主要介紹了
本地连接时,通过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?
朋友說他的一臺服務器上,裝了多個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?
總結
以上是生活随笔為你收集整理的本地连接时,通过localhost不能登陆到指定的端口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MemSQL初体验 - (3)性能测试
- 下一篇: RESET MASTER 和RESET