Solution to the problem that mysql local login cannot use port number to log in

Solution to the problem that mysql local login cannot use port number to log in

Recently, when I was using Linux to log in locally, I found that I could not log in normally and reported the following error message:

[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: Using mysql --verbose --help for analysis, it was found that the values ​​corresponding to port and socket were 0 or empty, that is, there were 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, in
port 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:

I don't know why the parameters added directly using -P on the command line are not used.

[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, just add the socket parameter in [client]. Adding only the port parameter will not work. The reason is currently unclear.

Summarize

The above is the solution to the problem that MySQL local login cannot use the port number to log in. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Tutorial diagram of checking and modifying the port number of mysql under Windows 10 system

<<:  Use crontab command in Linux environment to set up scheduled periodic execution tasks [including PHP execution code]

>>:  Detailed explanation of Vue ElementUI manually uploading excel files to the server

Recommend

How to compare two database table structures in mysql

During the development and debugging process, it ...

ElementUI implements sample code for drop-down options and multiple-select boxes

Table of contents Drop-down multiple-select box U...

How to ensure the overall user experience

Related Articles: Website Design for User Experien...

MySQL uses covering index to avoid table return and optimize query

Preface Before talking about covering index, we m...

Use iframe to display weather effects on web pages

CSS: Copy code The code is as follows: *{margin:0;...

Docker installation and deployment of Net Core implementation process analysis

1. Docker installation and settings #Install Cent...

Detailed explanation of how to view MySQL memory usage

Preface This article mainly introduces the releva...

Introduction to fuzzy query method using instr in mysql

Using the internal function instr in MySQL can re...

Node+Express test server performance

Table of contents 1 Test Environment 1.1 Server H...

Web front-end performance optimization

Web front-end optimization best practices: conten...

Detailed explanation of VUE's data proxy and events

Table of contents Review of Object.defineProperty...