ERROR 1007(HY000)第1行:无法创建数据库'mgsv';数据库存在

时间:2018-03-19 22:26:23

标签: java php mysql docker docker-compose

我将此original项目转换为docker-compose项目here,然后按照设置instructions进行设置。似乎我无法连接浏览器。

SQL file包含数据库架构,如下所示:

CREATE DATABASE mgsv;
CREATE USER 'mgsv_user'@'localhost' IDENTIFIED BY 'mgsvpass';
GRANT SELECT, INSERT, CREATE, DROP ON mgsv.* TO 'mgsvuser'@'localhost';
use mgsv;
CREATE TABLE IF NOT EXISTS `userinfo` (
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `email` text NOT NULL,
    `hash` text NOT NULL,
    `synfilename` text NOT NULL,
    `annfilename` text NOT NULL,
    `url` text NOT NULL,
    `session_id` text NOT NULL,
    `annImage`   int(5) NOT NULL,
    `create_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

docker-compose.yml看起来像这样:

version: '3.1'

services:
  db:
    image: mysql
    restart: always
    environment:
      - MYSQL_DATABASE=mgsv
      - MYSQL_USER=mgsv_user
      - MYSQL_PASSWORD=mgsvpass
      - MYSQL_ROOT_PASSWORD=mysql123
    volumes:
      - ./mysql:/docker-entrypoint-initdb.d

  www:
    build: ./mGSV 
    restart: always
    ports:
      - 8080:8080

Dockerfile包含PHP和所有其他工具设置,看起来像这样。

FROM php:5-apache

RUN apt-get update  && apt-get install -y --no-install-recommends \
                openjdk-7-jdk \
                maven  \
        git \
        && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/qunfengdong/mGSV.git

# Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
RUN cd /var/www/html/mGSV \
    && mkdir tmp \
    && chmod -R 777 tmp

RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php \ 
    && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php \
    && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

#Do not understand
#7. Cleanup scripts are provided to drop database synteny and annotation tables, remove entries from database table 'userinfo' and delete the folder containing image files which are older than 60 days. This task is accomplished by cron job to run the cleanup script every day. To create a cron job, use the command below:
#   shell> crontab -e

#At the last line of crontab, copy and paste the line below, and provide the exact path to mgsv/lib/cleanup.php
#   30 04 * * * /var/www/mgsv/lib/cleanup.php

#The script cleanup.php will be executed at 4:30 AM every morning.

#8. mGSV uses the mail function from PHP to send email to users. Speak to your system administrator to provide required information in the PHP configuration file called 'php.ini'.

#9. When installation completes, you can now open Install/index.php (i.e., http://<YOUR_SERVER_DOMAIN_NAME>/mgsv/Install/), which verifies prerequisites, database setup, and installation. YOUR_SERVER_DOMAIN_NAME refers to the domain name of your server.


RUN cd /var/www/html/mGSV/ws \
    && tar -xzf mgsv-ws-server.tar.gz

RUN cd /var/www/html/mGSV/ws/mgsv-ws-server \ 
    && mvn package

RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

RUN cd /var/www/html/mGSV/ws \ 
    && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties \
    && echo "ws_publish_url=http\://localhost\:8081/MGSVService" >> config.properties \
    && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

#To stop the web service
#shell> ps aux | grep ws-server-1.0RC1-jar-with-dependencies.jar
#*Note the process id from the output*
#shell> kill -9 <process id>

这是我得到的输出:

Attaching to mgsvdocker_www_1, mgsvdocker_db_1
www_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
www_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
www_1  | [Mon Mar 19 22:12:02.742360 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.34 configured -- resuming normal operations
www_1  | [Mon Mar 19 22:12:02.744224 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db_1   | Initializing database
db_1   | 2018-03-19T22:12:02.855291Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2018-03-19T22:12:03.251862Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1   | 2018-03-19T22:12:03.348644Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db_1   | 2018-03-19T22:12:03.411853Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8d99d2f8-2bc2-11e8-8ace-0242ac140003.
db_1   | 2018-03-19T22:12:03.414590Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
db_1   | 2018-03-19T22:12:03.415526Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db_1   | 2018-03-19T22:12:05.555076Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.555603Z 1 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.556433Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.557353Z 1 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.558712Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.559068Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.559557Z 1 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:05.560388Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | Database initialized
db_1   | Initializing certificates
db_1   | Generating a 2048 bit RSA private key
db_1   | ..........................................+++
db_1   | ...........................+++
db_1   | unable to write 'random state'
db_1   | writing new private key to 'ca-key.pem'
db_1   | -----
db_1   | Generating a 2048 bit RSA private key
db_1   | ....................................................................+++
db_1   | .................................................+++
db_1   | unable to write 'random state'
db_1   | writing new private key to 'server-key.pem'
db_1   | -----
db_1   | Generating a 2048 bit RSA private key
db_1   | ..........+++
db_1   | ...................................+++
db_1   | unable to write 'random state'
db_1   | writing new private key to 'client-key.pem'
db_1   | -----
db_1   | Certificates initialized
db_1   | MySQL init process in progress...
db_1   | 2018-03-19T22:12:09.627477Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2018-03-19T22:12:09.628759Z 0 [Note] mysqld (mysqld 5.7.21) starting as process 87 ...
db_1   | 2018-03-19T22:12:09.633134Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1   | 2018-03-19T22:12:09.634171Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2018-03-19T22:12:09.634378Z 0 [Note] InnoDB: Uses event mutexes
db_1   | 2018-03-19T22:12:09.634769Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1   | 2018-03-19T22:12:09.635298Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
db_1   | 2018-03-19T22:12:09.635485Z 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2018-03-19T22:12:09.636263Z 0 [Note] InnoDB: Number of pools: 1
db_1   | 2018-03-19T22:12:09.636914Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2018-03-19T22:12:09.639991Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1   | 2018-03-19T22:12:09.650561Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2018-03-19T22:12:09.660208Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2018-03-19T22:12:09.673096Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2018-03-19T22:12:09.697190Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2018-03-19T22:12:09.701919Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2018-03-19T22:12:09.754718Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2018-03-19T22:12:09.756113Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1   | 2018-03-19T22:12:09.756140Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1   | 2018-03-19T22:12:09.757786Z 0 [Note] InnoDB: Waiting for purge to start
db_1   | 2018-03-19T22:12:09.808245Z 0 [Note] InnoDB: 5.7.21 started; log sequence number 2551166
db_1   | 2018-03-19T22:12:09.809069Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2018-03-19T22:12:09.817123Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2018-03-19T22:12:09.822791Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180319 22:12:09
db_1   | 2018-03-19T22:12:09.834211Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1   | 2018-03-19T22:12:09.834819Z 0 [Warning] CA certificate ca.pem is self signed.
db_1   | 2018-03-19T22:12:09.846515Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.846560Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.846579Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.846613Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.846622Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.846640Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.853203Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.853233Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:09.890674Z 0 [Note] Event Scheduler: Loaded 0 events
db_1   | 2018-03-19T22:12:09.890927Z 0 [Note] mysqld: ready for connections.
db_1   | Version: '5.7.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
db_1   | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1   | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db_1   | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1   | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1   | 2018-03-19T22:12:13.111650Z 4 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.113784Z 4 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.115619Z 4 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.118409Z 4 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.118432Z 4 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.118458Z 4 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.118526Z 4 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.118543Z 4 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | 2018-03-19T22:12:13.219113Z 8 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222332Z 8 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222366Z 8 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222426Z 8 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222437Z 8 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222459Z 8 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222753Z 8 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2018-03-19T22:12:13.222768Z 8 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 
db_1   | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/mgsv.sql
db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | ERROR 1007 (HY000) at line 1: Can't create database 'mgsv'; database exists

我不确定docker-compose.yml内的Dockerfile文件或数据库配置是否出错。

任何机会,有谁知道我错过了什么?

提前谢谢

1 个答案:

答案 0 :(得分:2)

你有环境变量&#34; MYSQL_DATABASE = mgsv &#34;设置为 docker-compose.yml 文件中的mysql容器。创建并启动mysql容器时,它将自动创建数据库 mgsv ,并允许用户 mgsv_user (由环境变量指定&#34; MYSQL_USER = mgsv_user &#34;)访问它。有关详细信息,您可以查看official documentation以获取 mysql 图像。

你应该做的是,删除语句&#34; CREATE DATABASE mgsv; &#34;从您的SQL文件,或将该语句更改为&#34; 创建数据库,如果不是EXISTS mgsv; &#34;。您可能还需要调整该SQL文件中的其他语句(例如,在这种情况下不需要用户创建)。