Mysql需要以root身份运行(docker)

Mysql需要以root身份运行(docker)

我在运行 mysql docker 时遇到了一些问题。这是我的错误:

testmysql    | + echo 'Finished mysql_install_db'
testmysql    | Finished mysql_install_db
testmysql    | + pid=59
testmysql    | + mysql=(mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
testmysql    | + for i in '{30..0}'
testmysql    | + mysqld --verbose --skip-networking --socket=/var/run/mysqld/mysqld.sock
testmysql    | + echo 'SELECT 1'
testmysql    | + mysql --protocol=socket -uroot -hlocalhost '--socket=/var/run/mysqld/mysqld.sock --verbose'
testmysql    | + echo 'MySQL init process in progress...'
testmysql    | + sleep 1
testmysql    | MySQL init process in progress...
testmysql    | 2017-02-06 21:44:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
testmysql    | 2017-02-06 21:44:19 0 [Note] mysqld (mysqld 5.6.35) starting as process 59 ...
testmysql    | 2017-02-06 21:44:19 59 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
testmysql    | 
testmysql    | 2017-02-06 21:44:19 59 [ERROR] Aborting
testmysql    | 
testmysql    | 2017-02-06 21:44:19 59 [Note] Binlog end
testmysql    | 2017-02-06 21:44:19 59 [Note] mysqld: Shutdown complete

这是我的docker compose:

version: '2'

services:

 testmysql:
  build: 
    context: ./test-centos7-mysql
  image: test-centos7-mysql:latest
  container_name: testmysql
  environment:
    MYSQL_ROOT_PASSWORD: test
    MYSQL_DATABASE: test_db
    MYSQL_USER: usr_test
    MYSQL_PASSWORD: test
    MYSQL_HOST: localhost
  networks:
   test_network:
      ipv4_address: 172.16.250.1

networks:

 test_network:
   driver: bridge
   ipam:
     driver: default
     config:
     - subnet: 172.16.250.0/24
       gateway: 172.16.250.254

我的Dockerfile:

FROM centos:7

#Installation des packages de base
RUN yum install -y gcc \
        epel-release \
        make \
        net-tools 

#Installation Mysql 5.6
RUN wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
RUN rpm -ivh mysql-community-release-el7-5.noarch.rpm
RUN yum install -y mysql-community-server

# Nettoyage Yum
RUN yum clean all && rm -rf /tmp/yum*

#Copie du script de permissions
COPY ./container_files/fix_permissions.sh ./
RUN chmod -v +x /fix_permissions.sh
RUN ./fix_permissions.sh /var/lib/mysql/   && \
    ./fix_permissions.sh /var/run/

#Copie du script de création de DB
COPY ./container_files/docker-entrypoint.sh /
RUN chmod -v +x /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]

#On ouvre le port par défaut de mysql
EXPOSE 3306
CMD ["mysqld"]

版本:

[pedegand@localhost:~/docker-test]$ cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
[pedegand@localhost:~/docker-test]$ docker --version
Docker version 1.13.0, build 49bf474
[pedegand@localhost:~/docker-test]$ docker-compose --version
docker-compose version 1.9.0, build 2585387

我见过几篇帖子有同样的错误(https://github.com/docker-library/mysql/issues/216https://github.com/docker-library/mysql/issues/45),但我不认为我有同样的问题(没有挂载并且MYSQL_HOST设置为localhost)。

答案1

/usr/libexec/mysqld --user=root

应该可以工作。描述于在线手册页

相关内容