Get the App
SLTechnology News&Howtos  ›  Database  › 

How to log in to mysql locally using a port number

Shulou Source: shulou.com Published: 2022-05-31 23:41:45 09月11日 Update

This article introduces how to use the port number to log in to mysql locally. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Recently, when I logged in locally using linux, I found that the login could not be done properly, and the following error message was reported:

[root@xxxx] # mysql-h localhost-u root-p-P 3306

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/ tmp/mysql.sock' (2)

Analysis: use mysql-- verbose-- help to analyze, only to find that the corresponding values of port and socket are both 0 or empty, that is, there are no default parameters.

[root@UHDEV013] # mysql-verbose-help | grep socket-protocol=name The protocol to use for connection (tcp, socket, pipe,-S,-- socket=name The socket file to use for connection. The buffer size for TCP/IP and socket communication.socket [root@xxxxx ~] # mysql-- verbose-- help | grep port-P,-- port=# Port number to use for connection or 0 for default to, inport 0

When logging in to mysql, you need to find the relevant parameters from the configuration file before you can get the default parameters. The location of the parameter file is as follows:

For the direct use of the parameters appended with-P in the command exercise, why not, I do not know why.

[root@UHDEV013] # mysql-- verbose-- help | grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT,/etc/my.cnf / etc/mysql/my.cnf / usr/haier/mysql/etc/my.cnf / usr/haier/mysql/my.cnf ~ / .my.cnf

Solution:

In the / etc/my.cnf file, you can add the socket parameter to [client], but only the port parameter does not work.

On how to use the local port number to log in to mysql to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Parameters login files slogans content more analysis help yes no that is location information interests reasons commands guys buddies articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Redmi macOS Shulou Tech Info