[Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

After changing the environment recently, the docker reported an error when installing mysql8. The solution is as follows

Find my.cnf to modify

# Add the data
[client]
# Default character set
#default-character-set=utf8
socket= /var/run/mysqld/mysqld.sock 

[mysql]
# Default character set
#default-character-set=utf8
socket= /var/run/mysqld/mysqld.sock #### Here the original configuration is written above [client]
#socket= /storage/db/mysql/mysql.sock
[mysqld]
#
server-id=01
port=3306
## Turn on binary logging
log-bin=mysql-slave-bin
## relay_log configuration relay log
relay_log=edu-mysql-relay-bin
# Ignore case
lower_case_table_names=1

pid-file= /var/run/mysqld/mysqld.pid

socket= /var/run/mysqld/mysqld.sock
#socket= /storage/db/mysql/mysql.sock
# Database data storage directory
datadir= /var/lib/mysql

secure-file-priv= NULL

# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links=0
# Maximum number of links
max_connections=200
# Maximum number of failures
max_connect_errors=10
# Default time zone
default-time_zone='+8:00'

character-set-client-handshake=FALSE

character_set_server=utf8mb4

# default-character-set=utf8

collation-server=utf8mb4_unicode_ci

init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'

# Default authentication with 'mysql_native_password' plugin
default_authentication_plugin= mysql_native_password

# Custom config should go here
!includedir /etc/mysql/conf.d/

Similar Posts: