【发布时间】:2021-11-13 03:37:03
【问题描述】:
我在 a2 主机中使用 VPS Ubuntu 20.04。我正在尝试设置我的 mysql 数据库,但我遇到了一些错误。我正在通过 SSH 执行此操作。我安装了 mysql 使用
sudo apt-get install mysql-server mysql-client
它安装得很好。但是当我尝试运行时
sudo mysql_secure_installation
它抛出了这个错误
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
我尝试重新安装mysql-server,但没有成功。我注意到一些错误:
它没有任何关于套接字的信息。
- 我的 /var/run/mysqld/mysqld.sock 文件在我安装数据库时没有创建。甚至没有创建文件夹 /var/run/mysqld。我试图创建两者,但它仍然不起作用。在我的示例中,文件是以错误的方式创建的,甚至没有被创建。我不知道为什么会这样。
文件:/etc/mysql/mysql.conf.d/mysqld.cnf
#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[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.sock 没有创建并且我的 my.cnf 不完整。这两个文件默认是错误的。
-
您的
my.cnf文件不完整。它包括两个目录路径以及更多文件,这些文件将包含在mysql和mysqld的配置中。您将在其中一个文件中找到套接字详细信息。 -
哦。我从 /etc/mysql/mysql.conf.d 读取文件并找到包含一些信息的文件 mysqld.cnf。它也有通往套接字的路径。我现在该怎么办?该文件的内容不应该在 /etc/mysql/my.cnf 中吗?我编辑了帖子并将文件放在那里。
-
编辑
my.cnf文件可能无害,但也不是必需的。 MySQL 将自动包含额外的文件。这就是!includedir指令的目的。