“mysql -u a -p -S /var/run/mysqld/mysqld.sock”有效,但“mysql -u a -p”无效

问题描述 投票:0回答:1

当我使用以下命令时:

mysql -u a -p -S /var/run/mysqld/mysqld.sock

它有效,但如果我不指定

-S /var/run/mysqld/mysqld.sock
,它会给我以下错误:

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

我还记得我上次使用这台电脑时(可能是一个月前)它可以工作,但今天我尝试了它,但它不起作用!

问题是什么以及如何解决?

EDIT
:这是
/etc/mysql/my.cnf

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

这是

/etc/mysql/mysql.conf.d/mysql.cnf
:

[mysql]

这是

/etc/mysql/mysql.conf.d/mysqld.cnf
:

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port            = 3306
datadir = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir                = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
mysqlx-bind-address     = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size         = 16M
# max_allowed_packet    = 64M
# thread_stack          = 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log                = 1
# slow_query_log_file   = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id             = 1
# log_bin                       = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db          = include_database_name
# binlog_ignore_db      = include_database_name
mysql ubuntu connect
1个回答
0
投票

我可以通过将以下代码添加到

/etc/mysql/mysql.conf.d/mysqld.cnf
文件末尾来解决该问题。

[client]
socket=/var/run/mysqld/mysqld.sock
© www.soinside.com 2019 - 2024. All rights reserved.