前提・実現したいこと
DOCKERコンテナにてmysqlデータベースを構築したいのですが、エラーを吐きます。
スクリプトでやっているのが原因かと思い、手動でもやりましたが同じところで止まってしまいます。
お手数ですがご教授ください。
発生している問題・エラーメッセージ
root@63b3034ffffb:/# sh docker-entrypoint-initdb.d/DBSet.sh mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1049 (42000) at line 1: Unknown database 'Alva_Server' mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCE D_Bookshelf(id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB' at line 11 mysql: [Warning] Using a password on the command line interface can be insecure. root@63b3034ffffb:/#
これのこの部分が理解できません。
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCE D_Bookshelf(id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB' at line 11
該当のソースコード
DBset.sh
bash
1#!/usr/bin/env bash 2mysql -u root -ppassword -e "drop database Alva_Server" #テスト用 3if ! mysql -u root -ppassword -e "use Alva_Server"; then 4 mysql -u root -ppassword -e "create database Alva_Server" 5 mysql -u root -ppassword Alva_Server < /usr/local/lib/SQL_schfiles/BookShelf_scheme.sql 6 mysql -u root -ppassword Alva_Server < /usr/local/lib/SQL_schfiles/BookData_scheme.sql 7 mysql -u root -ppassword Alva_Server < /usr/local/lib/SQL_schfiles/Barcode_data.sql 8fi
BookShelf_scheme.sql
sql
1CREATE TABLE D_BookShelf ( 2 `id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 `XGrid_Place` int(10) NOT NULL DEFAULT '0', 4 `YGrid_Plave` int(10) NOT NULL DEFAULT '0', 5 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 6 `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 7) ENGINE=InnoDB;
BookData_scheme.sql
sql
1CREATE TABLE D_Bookdata ( 2 `barcode` int primary key, 3 `id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, 4 `book_id` int(10), 5 `exist_S` int(1) DEFAULT '0', 6 `book_title` varchar(100) DEFAULT 'NOT INPUTED', 7 `book_genre` varchar(15) DEFAULT 'NOT INPUTED', 8 `book_author` varchar(15) DEFAULT 'NOT INPUTED', 9 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 10 `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 11 FOREIGN KEY (book_id) REFERENCE D_Bookshelf(id) 12 ON DELETE CASCADE ON UPDATE CASCADE 13) ENGINE=InnoDB;
Barcode_data.sql
sql
1CREATE TABLE D_Barcode ( 2 `Number` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 `Barcode` int(255) NOT NULL, 4 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 5 `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 6) ENGINE=InnoDB;
試したこと
スクリプトにしたせいかと思いMYSQL内で手動で同じことをしましたが全く同じエラーが出力されました。
補足情報
mysqlバージョンなど
mysqladmin Ver 8.42 Distrib 5.7.23, for Linux on x86_64 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.7.23 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 20 min 50 sec Threads: 1 Questions: 62 Slow queries: 0 Opens: 111 Flush tables: 1 Open tables: 102 Queries per second avg: 0.049
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。