mysql specifies the login port but logs in to another port-two login methods of mysql

Try to log in to port 3308

[root@lzl mysql]# mysql -P 3308 -uroot -poracle
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 23
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> 
mysql> show variables like '%port%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_support_xa        | ON    |
| large_files_support      | ON    |
| port                     | 3306  |
| report_host              |       |
| report_password          |       |
| report_port              | 3306  |
| report_user              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.15 sec)

It seems to be logged in, but I log in and find that the port is 3306

It feels very strange, --help checked -P is indeed the designated port

 

Add a space to try

[root@lzl mysql]# mysql  -uroot -poracle -P 3308
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 25
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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                     | 3306  |
| report_host              |       |
| report_password          |       |
| report_port              | 3306  |
| report_user              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.00 sec)

Still 3306

 

Later, I thought that it might be a socket problem, so I specified socket login

[root@lzl mysql]# mysql  -uroot -poracle -P 3308 -S/tmp/mysql3308.sock

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              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.00 sec)

Successful landing! ! !

 


Try not to specify the port, only the socket

[root@lzl mysql]# mysql  -uroot -p  -S/tmp/mysql3308.sock       
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.00 sec)

mysql> 

Can also

 

Question: Why do I log in to 3306 when my -P specifies port 3308?

When I specified -P3308, mysql went to find the default socket /tmp/mysql.sock. This socket was my 3306, so I logged in to 3306.

 

to sum up:

1. There are two ways to log in to mysql, socket and tcp/ip.

2. Sockets are generally used for local login, sockets are local files, and each mysql instance has a socket. For example, if mysql -uroot -poracle is not specified, the file /tmp/mysql.sock is used by default. As long as you don't specify -h, you will log in using socket
3. There is also a method of tcp/ip, which is generally used for remote login. As long as -h host is specified, mysql will use tcpip to log in to the database. Even if the machine specifies -h, it is also tcp/ip login

 

So I did some experiments:
if you log in remotely, you should specify -P port directly, no need to specify socket
[root@lzl ~]# mysql -h192.168.43.6 -P3308 -uroot -poracle
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 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.06 sec)

mysql> 

 

So, there are now 2 ways to log in to the 3308 port database

mysql -hlocalhost -P3308 -uroot -poracle

mysql -S/tmp/mysql3308.sock -uroot -poracle

Guess you like

Origin blog.csdn.net/qq_40687433/article/details/107771142