docker 启动MySQL Please read "Security" section of the manual to find out how to run mysqld as root! 报错

docker-compose 部署mysql 容器
报错
Please read "Security" section of the manual to find out how to run mysqld as root!
直观解释,就是不让你使用root进行mysql启动
我的compose文件

version: "2"

services:
  mysql:
    image: mysql:5.7.11
    container_name: mysql
    restart: always
    hostname: mysql
    mem_limit: 2g
    ports:
     - 33306:3306
    volumes:
     - /etc/localtime:/etc/localtime
     - $PWD/conf/my.cnf:/etc/mysql/my.cnf
     - $PWD/data/mysql:/var/lib/mysql
     - $PWD/sqldumps:/sqldumps
    environment:
     - MYSQL_ROOT_PASSWORD=passwd

我以往启动的时候,不会有这个错,百度了很久,都说要更换启动的用户,
但是容器部署的,我并找不到我的my.cnf在哪里,所以,这里困扰了我很久
那么,如果没有的话,想到是不是可以自己创建,自己找了以往项目上的配置文件,在挂载目录mysql配置文件的目录进行创建一个my.cnf
我很奇怪的就是,为什么此次没有自动创建my.cnf,
【哦,我知道了,以往项目,启动容器的用户不是root,而容器mysql默认以uid为xxx的用户执行,我是root 所以,用root启动不来。】
我可以在配置文件中指定用户即可,默认user=mysql
下面是my.cnf的样例

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# 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

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#


[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
default-character-set=utf8
[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0
[mysqld]
character-set-server=utf8
max_connections = 5000
skip-host-cache
skip-name-resolve
innodb_buffer_pool_size = 512m
#skip-grant-tables
group_concat_max_len = 1024000
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp=false
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
slow_query_log = 1
slow_query_log_file = /tmp/mysql_slow.log
long_query_time = 2
#log_bin         = mysql-bin
#server_id       = 24
#bind-address   = 127.0.0.1
log-error       = /var/log/mysql/error.log
symbolic-links=0

#!includedir /etc/mysql/conf.d/
#!includedir /etc/mysql/mysql.conf.d/
posted @ 2022-03-10 16:45  darling331  阅读(522)  评论(0编辑  收藏  举报