Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Problem with entrypoint.sh #17

Closed
maxisme opened this issue Dec 24, 2018 · 1 comment
Closed

Problem with entrypoint.sh #17

maxisme opened this issue Dec 24, 2018 · 1 comment

Comments

@maxisme
Copy link

maxisme commented Dec 24, 2018

Whenever

  db:
    image: hypriot/rpi-mysql
    ports:
      - "32000:3306"
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=foo
      - MYSQL_DATABASE=bar
      - MYSQL_USER=demouser
      - MYSQL_PASSWORD=demopassword
    volumes:
      - ./db/schema:/docker-entrypoint-initdb.d/:ro

Inside /db/schema I have 1.sql:

USE `bar`;

CREATE TABLE `Logs` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_message` varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `message` text COLLATE utf8_bin,
  `read` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
);

I receive the error:

ERROR: 1064 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 '' at line 1

When I use the tobi312/rpi-mysql image everything works as expected.

Inside the container when runnning:

$ cat /tmp/mysql-first-time.sql 

I get:

DELETE FROM mysql.user ;
CREATE USER 'root'@'%' IDENTIFIED BY 'demopassword' ;
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
DROP DATABASE IF EXISTS test ;
CREATE DATABASE IF NOT EXISTS `bar` ;
CREATE USER 'demouser'@'%' IDENTIFIED BY 'demopassword' ;
GRANT ALL ON `bar`.* TO 'demouser'@'%' ;
FLUSH PRIVILEGES ;
USE `bar`;

CREATE TABLE `Logs` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_message` varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `message` text COLLATE utf8_bin,
  `read` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
);

Which seems to have no syntax error other than the space?

@DumDumin
Copy link

DumDumin commented Jul 3, 2019

Each line in your .sql file needs to be a complete sql statement... took me forever...
Your Create Table statement needs to be in only one line.
Here is a reference to the official documentation https://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_init-file

@maxisme maxisme closed this as completed Jul 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants