-1

I am receiving 'no such file or directory' when I start mysql even though the file exists in the correct directory.

thescript:

#!/bin/bash

/usr/bin/docker exec -i mysql /bin/bash <<EOF
mysql -uroot -ppasswd 
CREATE DATABASE theDB CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES on theDB.* to user@'%' IDENTIFIED BY 'passwd';
FLUSH PRIVILEGES;
EOF

docker.yml:

version: "2"
services:
  mysql:
    image: mysql:latest
    restart: always
    container_name: mysql
    environment:
      -  MYSQL_ROOT_PASSWORD=passwd
    volumes:
      -  /temp/mysql_cnf:/etc/mysql/mysql.conf.d
    ports:
      -  3306:3306
    command: /bin/sh -c "chmod +x /home/user/mysql-container/thescript.sh && /bin/sh /home/user/mysql-container/thescript.sh"

~

George
  • 5,808
  • 15
  • 83
  • 160
  • you can get the (misleading) error message "no such file or directory" if the architecture does not match, e.g. if you try to execute a 64bit binary on a 32bit system or vice versa – Karsten Koop Apr 11 '17 at 08:15

2 Answers2

0

At first glance, I would suspect it is because your inlined segment is being interpreted as multiple commands. Try adding a "\" to inhibit EOL:

/usr/bin/docker exec -i mysql /bin/bash <<EOF
mysql -uroot -ppasswd  \
CREATE DATABASE theDB CHARACTER SET utf8 COLLATE utf8_general_ci; \
GRANT ALL PRIVILEGES on theDB.* to user@'%' IDENTIFIED BY 'passwd'; \
FLUSH PRIVILEGES; 
EOF
Wayne Vosberg
  • 1,023
  • 5
  • 7
0

CREATE is not a valid Bash command. The Bash wrapper shell seems superfluous here anyway.

#!/bin/bash    
/usr/bin/docker exec -i mysql mysql -uroot -ppasswd <<'EOF'
CREATE DATABASE theDB CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES on theDB.* to user@'%' IDENTIFIED BY 'passwd';
FLUSH PRIVILEGES;
EOF
tripleee
  • 175,061
  • 34
  • 275
  • 318