【问题标题】:mysql on docker: Can't start server : Bind on unix socket: Invalid argumentdocker上的mysql:无法启动服务器:在unix套接字上绑定:无效的参数
【发布时间】:2022-07-24 01:12:51
【问题描述】:

我有 docker compose yaml:

version: "3.8"
services:
  mysql:
    image: mysql/mysql-server:8.0.27
    container_name: javanotifications_mysql
    volumes:
      - ./persistence/mysql_db:/var/lib/mysql

运行后

docker compose up

我明白了

[Entrypoint] MySQL Docker Image 8.0.27-1.2.6-server
[Entrypoint] Starting MySQL 8.0.27-1.2.6-server
2022-04-22T23:45:52.061082Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
2022-04-22T23:45:52.065609Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2022-04-22T23:45:52.077805Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-04-22T23:45:52.534236Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-22T23:45:52.803994Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-04-22T23:45:52.804064Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-04-22T23:45:52.808602Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-04-22T23:45:52.808689Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-04-22T23:45:52.818496Z 0 [ERROR] [MY-010270] [Server] Can't start server : Bind on unix socket: Invalid argument
2022-04-22T23:45:52.818539Z 0 [ERROR] [MY-010258] [Server] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
2022-04-22T23:45:52.818778Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-04-22T23:45:54.322278Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27)  MySQL Community Server - GPL.

容器死亡。

清理“持久性”目录并重复该过程后一切都一样

我唯一想到的是 /var/lib/mysql/mysql.sock 有一些问题,mysql 不喜欢(可能)将它放在挂载目录中。

那么问题来了,如何告诉 mysql 在容器中的其他位置创建它 - 除了挂载目录 /var/lib/mysql/?

Docker version 20.10.14, build a224086
MacBook Pro 16-inch, 2019, 2.4 GHz 8-Core Intel Core i9
macOS Big Sur version 11.6

--------- 编辑 -----

因此,根据 Sergio Santiago 下面提供的建议,我最终得到了这个解决方案,它完美地工作,消除了这个错误:

version: "3.8"
services:
  mysql:
    image: mysql/mysql-server:8.0.27
    container_name: javanotifications_mysql
    ports:
      - "${MYSQL_PORT}:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_PASS}
      MYSQL_ROOT_HOST: "%"
    volumes:
      - ./mysql/my.cnf:/etc/my.cnf
      - ./mysql_db/${PROJECT_NAME}:/var/data

mysql/my.cnf哪里有这个内容

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

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



# modified by US VVV
# NOTE: original localization of the my.cnf in the image is /etc/my.cnf
datadir=/var/data

【问题讨论】:

  • 你的 Docker 主机是什么?视窗? Linux?麦克...?
  • 我提供了有关环境的信息

标签: mysql docker docker-compose


【解决方案1】:

您可以通过 mysqld 配置进行设置。

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

如果它不起作用,您可以查看其他类似问题here

【讨论】:

    猜你喜欢
    • 2014-01-12
    • 2018-07-21
    • 2022-12-12
    • 2017-08-01
    • 1970-01-01
    • 2017-05-09
    • 2014-11-21
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多