Mysql 5.7 无法创建 unix 套接字锁定文件
Posted
技术标签:
【中文标题】Mysql 5.7 无法创建 unix 套接字锁定文件【英文标题】:Mysql 5.7 Could not create unix socket lock file 【发布时间】:2017-08-14 06:55:25 【问题描述】:我正在尝试在同一个 Ubuntu 16.10 32 位机器中创建多个 mysql 5.7 实例。我已将原始数据目录复制到新目录。为新实例创建了单独的日志文件夹(日志正在工作)。将新数据目录 /var/lib/mysql2 和日志目录 /var/log/mysql2/ 的所有者更改为 mysql:mysql。我已经删除了应用装甲。我只是在浏览了其他 SO 答案后才发布了这个问题……这些都没有解决多实例问题。
这是我的 my2.cnf:
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld2.pid
socket = /var/run/mysqld/mysqld2.sock
port = 3307
basedir = /usr
datadir = /var/lib/mysql2
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# 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
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
#max_connections = 100
#table_open_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
[mysqld_safe]
socket = /var/run/mysqld/mysqld2.sock
nice = 0
如您所见,我已将端口分别更改为 3307 和其他端口。现在当我运行时(必须将 sudo 添加到 mysqld):
sudo mysqld --defaults-file=/etc/mysql/my2.cnf &
我收到:
2017-03-22T08:31:21.684121Z 0 [Note] mysqld (mysqld 5.7.17-0ubuntu0.16.10.1) starting as process 13676 ...
2017-03-22T08:31:21.687115Z 0 [Note] InnoDB: PUNCH HOLE support available
2017-03-22T08:31:21.687131Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-03-22T08:31:21.687135Z 0 [Note] InnoDB: Uses event mutexes
2017-03-22T08:31:21.687140Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2017-03-22T08:31:21.687143Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-03-22T08:31:21.687147Z 0 [Note] InnoDB: Using Linux native AIO
2017-03-22T08:31:21.687281Z 0 [Note] InnoDB: Number of pools: 1
2017-03-22T08:31:21.687344Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2017-03-22T08:31:21.688116Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-03-22T08:31:21.693801Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-03-22T08:31:21.694846Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the $
2017-03-22T08:31:21.708807Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-03-22T08:31:21.776053Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-03-22T08:31:21.776228Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-03-22T08:31:21.825266Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2017-03-22T08:31:21.826338Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-03-22T08:31:21.826359Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-03-22T08:31:21.826695Z 0 [Note] InnoDB: Waiting for purge to start
2017-03-22T08:31:21.880277Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 2535531
2017-03-22T08:31:21.881286Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql2/ib_buffer_pool
2017-03-22T08:31:21.881581Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-03-22T08:31:21.887687Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170322 14:01:21
2017-03-22T08:31:21.890330Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without cer$
2017-03-22T08:31:21.890380Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3307
2017-03-22T08:31:21.890407Z 0 [Note] - '127.0.0.1' resolves to '127.0.0.1';
2017-03-22T08:31:21.890695Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2017-03-22T08:31:21.890791Z 0 [ERROR] Could not create unix socket lock file /var/run/mysqld/mysqld2.sock.lock.
2017-03-22T08:31:21.890807Z 0 [ERROR] Unable to setup unix socket lock file.
2017-03-22T08:31:21.890819Z 0 [ERROR] Aborting
我错过了什么?
【问题讨论】:
mysql用户可以写信给/var/run/mysqld/
吗?
是...该目录归mysql:mysql所有
...并且拥有rwx...
之类的权限,并且套接字文件不存在且权限或所有权错误?
原始 .sock 文件没有可执行权限(rw)。我也看不到文件夹中的mysql2.sock。
如果是我,我会在strace
下启动mysqld,以查看正在进行的调用以及返回的错误。这将产生大量输出,但由于 mysqld 正在关闭,因此不应无法管理。
【参考方案1】:
检查是否有锁文件
ls /var/run/mysqld/mysqld2.sock.lock
1。如果存在
1.1 检查哪个进程使用了锁文件
lsof /var/run/mysqld/mysqld2.sock.lock
1.1.1 如果没有进程使用锁文件
rm 锁定文件rm /var/run/mysqld/mysqld2.sock.lock
然后启动mysql
1.1.2 如果有进程使用锁文件
将lock file and socket file
更改为另一条路径
2。如果不存在
需要更多信息来检查正在发生的事情strace -ff mysqld --defaults-file=/etc/mysql/my2.cnf
【讨论】:
【参考方案2】:对于那些使用 apparmor 的人,/etc/apparmor.d/usr.sbin.mysqld
中的以下权限允许 mysqld 创建和使用锁定文件。
/var/run/mysqld/mysqld2.pid rw,
/var/run/mysqld/mysqld2.sock rw,
/var/run/mysqld/mysqld2.sock.lock rw,
然后以 root 身份运行以下命令以重新加载配置文件。
apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
由于某种原因,我在没有rw
对所有这三个文件的权限的情况下得到了 OP 的错误。
【讨论】:
以上是关于Mysql 5.7 无法创建 unix 套接字锁定文件的主要内容,如果未能解决你的问题,请参考以下文章