How can I find out which Transport Protocol MySQL is using? I know how I can change it but I don't know how to show the current one.
2 Answers
There are two passive ways to find that out
- Connection Status
- MySQL Prompt
EXAMPLE
If you execute the status command (\s)
mysql> \s
you get this output
MySQL://localhost/root/mysqld.sock/(none)> \s
--------------
mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.26 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 10 min 57 sec
Threads: 1 Questions: 24 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 28 Queries per second avg: 0.036
MySQL://localhost/root/mysqld.sock/(none)>
Just under Protocol version, you see how I am connected:
Protocol version: 10
Connection: Localhost via UNIX socket
Another method would be to look at your MySQL prompt, provided you configured the prompt display. Please note my current prompt:
MySQL://localhost/root/mysqld.sock/(none)>
I have it set in .my.cnf under the [mysql] group header
[mysql]
prompt="MySQL://\h/\u/\p/\d> "
The \h echoes the host address and \p echoes the port number in use. in my case, since it echoes localhost and mysqld.sock , it is not using TCP/IP. If it were using TCP/IP, it should echo 127.0.0.1 and 3306.
If you want to try connect with TCP/IP, you have to use --protocol as you mentioned:
#> mysql -h127.0.0.1 --protocol=tcp -uroot -p
- 185,223
- 33
- 326
- 536
I don't think there is a variable for that.
As it makes basically no different, if you use on a local machine (names pipes windows only / Sockets linux only ) or tcp/ip.
When you try to connect from another machine you can use only tcp/ip
When you connect to a local host with -h localhost then the client will first try to use names pipes/sockets and when that fails it will try tcp/ip.
If you connect with -h 127.0.0.1 the client will use only tcp/ip
- 8,699
- 6
- 14
- 27