docker-compose启动mysql容器error.log无权限访问
docker-compose 运行mysql 容器的时候一直报下面的错误:
.../var/log/mysql/mysql-error.log' for error logging: Permission denied"
出现这个问题,主要是容器中启动MySQL 服务的是 mysql 用户.而我们宿主机中是没有mysql 这个用户存在的,所以产生了 Permission denied 这个错误类型.
解决办法:
cat >/root/soft_shell/mysql/docker-compose.yml<<EOF version: "3" services: mysql: image: mysql:5.7 container_name: mysql ports: - 3306:3306 privileged: true environment: MYSQL_ROOT_PASSWORD: root volumes: - /etc/localtime:/etc/localtime:ro - /data/mysql/log:/var/log/mysql:rw - /data/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw - /data/mysql/data:/var/lib/mysql command: - "--default-authentication-plugin=mysql_native_password" entrypoint: bash -c "chown -R mysql:mysql /var/log/mysql && exec /entrypoint.sh mysqld" restart: always EOF
说明:
command 用来指定mysql容器启动后默认执行的命令,entrypoint 用来启动容器后需要执行的命令.
只要添加这行就可以解决问题
entrypoint: bash -c "chown -R mysql:mysql /var/log/mysql && exec /entrypoint.sh mysqld"
ps:
再给大家一个mysql配置文件
cat >/data/mysql/conf/my.cnf<<EOF [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql lower_case_table_names=1 #实现mysql不区分大小(开发需求,建议开启) # Disabling symbolic-links is recommended to prevent assorted security risks default-time_zone = '+8:00' # 更改字符集 如果想Mysql在后续的操作中文不出现乱码,则需要修改配置文件内容 symbolic-links=0 skip-host-cache skip-name-resolve character-set-server=utf8mb4 [mysqldump] quick quote-names max_allowed_packet = 16M [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 EOF
评论: