MySQL Commands in Shell Script

0

I'm trying to do a routine to deploy an application, and I came across a problem in the shell script, the mysql-related commands I can not execute inside the same, but at the prompt they work, what should be done? >

mysql -u sdesk_autoinstall -pSENHA;
CREATE DATABASE $1;
echo "Database $1 created"
CREATE USER '$1'@'localhost' IDENTIFIED BY '$2';
GRANT ALL PRIVILEGES ON $1 . * TO '$1'@'localhost';
echo "User permission inserted"
use $1;
source /var/www/app.dominio.com/install/db/db_demo.sql;
mkdir /var/www/app.dominio.com.br/html/$1
    
asked by anonymous 16.08.2018 / 13:22

1 answer

3

You can try as follows:

mysql -u USUARIO -pSENHA NOMEBANCO -e "QUERY QUE VOCÊ QUER EXECUTAR NO MYSQL"

ex:

mysql -u user -psenha  mysql -e "select * from user;"
    
16.08.2018 / 19:32