title: Shell script: MySQL command inside a container
body: <p>I am trying to automate some tasks utilizing shell. I'm getting trouble when I try to run a MySQL command inside a container.</p>
  <pre><code>#!/usr/bin/env bash
  
  read -p &quot;Username : &quot; WEBUSER
  read -p &quot;User password : &quot; USERPASSWD
  read -p &quot;Database name : &quot; DBNAME
   
  RTPASSWD=`docker exec -it $(docker ps -f name=mysql -q) cat /run/secrets/password`
  
  docker exec -it $(docker ps -f name=mysql -q) mysql -u root -p${RTPASSWD} -Bse &quot; CREATE USER '${WEBUSER}'@'%' IDENTIFIED BY '${USERPASSWD}' ; CREATE DATABASE ${DBNAME}; GRANT ALL ON ${DBNAME}.* TO '${WEBUSER}'@'%' &quot;
  </code></pre>
  <p>When I run the script I get the MySQL man. I think it doesn't recognize the MySQL commands because of the ('), but now I don't know how to do it.</p>
  <pre><code>MySQL  Ver 15.1 Distrib 10.4.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
  Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  
  Usage: mysql [OPTIONS] [database]
  
  Default options are read from the following files in the given order:
  /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
  The following groups are read: mysql mariadb-client client client-server client-mariadb
  The following options may be given as the first argument:
  --print-defaults          Print the program argument list and exit.
  --no-defaults             Don't read default options from any option file.
  The following specify which files/extra groups are read (specified before remaining options):
  --defaults-file=#         Only read default options from the given file #.
  --defaults-extra-file=#   Read this file after the global files are read.
  --defaults-group-suffix=# Additionally read default groups with # appended as a suffix.
  .
  .
  .
  
  </code></pre>
  <p>Someone can help me, please?</p>