Mysql commands in Shell Script

Asked

Viewed 414 times

0

I am trying to make a routine to deploy an application, and I came across a problem in shell script, the mysql commands I can’t run inside it, but at the prompt work, which 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

1 answer

3

You can try this way:

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

ex:

mysql -u user -psenha  mysql -e "select * from user;"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.