unix系統上,mysql的登錄方式有兩種,分別是socket和tcp/ip方式登錄。
當server和client在同一臺服務器上的時候,咱們能夠直接用mysql命令登錄。html
[root@mysql ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.46-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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. root@[(none)]>
當什麼參數都沒有指定的時候,mysql默認使用socket方式登錄,若是my.cnf的[client]沒有指定socket文件路徑時,mysql默認會去尋找/tmp/mysql.sock,因此若是mysql服務啓動的時候,生成的socket文件不是默認路徑的話,登錄會報錯。mysql
[root@mysql ~]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysql服務啓動的時候,socket文件的生成目錄能夠在[mysqld]上指定,若是沒有指定,默認是/tmp/mysql.sock;
mysql登錄的時候,指定參數-h,會使用tcp/ip的方式鏈接,若是沒有指定端口的話,默認是使用3306端口sql
[root@mysql ~]# mysql -h192.1.1.20 ERROR 2003 (HY000): Can't connect to MySQL server on '192.1.1.20' (111) [root@mysql ~]# mysql -h192.1.1.20 -P3307 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.5.46-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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. root@[(none)]>
當mysql登錄時,同時指定-h和-S,mysql會默認使用tcp/ip的方式鏈接。服務器
[root@mysql ~]# mysql -h192.1.1.20 -P3307 -S /ddd/sdfs.scok Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.46-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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. root@[(none)]>
隨便指定一個socket文件均可以登錄。socket
能夠查看簡潔版的:MySQL 鏈接方式tcp
更多細節能夠查看 :http://blog.itpub.net/15480802/viewspace-1755100/spa