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 load third-party component libraries on demand in Vue3

Preface Take Element Plus as an example to config...

How to use Linux to calculate the disk space occupied by timed files

Open the scheduled task editor. Cent uses vim to ...

Explanation of the working mechanism of namenode and secondarynamenode in Hadoop

1) Process 2) FSImage and Edits Nodenode is the b...

Explanation of MySQL's horizontal and vertical table partitioning

In my previous article, I said that the optimizat...

How to use Vue-router routing

Table of contents 1. Description 2. Installation ...

Docker starts Redis and sets the password

Redis uses the apline (Alps) image of Redis versi...

Vite introduces the implementation of virtual files

Table of contents background Importing virtual fi...

Let's talk about parameters in MySQL

Preface: In some previous articles, we often see ...

Implementing Priority Queue in JavaScript

Table of contents 1. Introduction to priority que...

Summary of Docker Consul container service updates and issues found

Table of contents 1. Container service update and...

Vue implements simple calculator function

This article example shares the specific code of ...

MySQL 5.7 mysql command line client usage command details

MySQL 5.7 MySQL command line client using command...