Enviado em 07/02/2019 - 17:45h
Olá, estou criando um script pra criar usuarios automaticamente no banco... porém sempre estou batendo com um erro
mysql=`which mysql`
DB_user="user"
db_m="user"
pass_user="xxxxxxx"
PASS_user="yyyyyy"
HOST="host.banco.com.br"
db="db.de.destino.com.br"
dbSenha="senhadb"
sqlFlush="flush privileges"
dbName=`cat /local/aonde/pega/o/nomedousuario.txt | grep dbname | cut -d[ -f3 | cut -d] -f1 | head -n1`
dbUser=`cat /local/aonde/pega/o/nomedobanco.txt | grep username | cut -d[ -f3 | cut -d] -f1 | head -n1`
sqlCriarUsuario="CREATE USER '$dbUser'@'localhost' IDENTIFIED BY '$dbSenha';"
sqlCriarDB="CREATE DATABASE IF NOT EXISTS $dbName;"
sqlPermissao1="GRANT ALL PRIVILEGES ON $dbName.* TO '$dbUser'@'localhost' IDENTIFIED BY '$dbSenha';"
sqlPermissao2="GRANT ALL PRIVILEGES ON $dbName.* TO '$dbUser'@'10.0.%' IDENTIFIED BY '$dbSenha';"
sqlPermissao3="GRANT ALL PRIVILEGES ON $dbName.* TO '$dbUser'@'xxx.xxx.xxx.xx' IDENTIFIED BY '$dbSenha';"
echo "Criando usuario, banco e setando permissoes"
$mysql --host=$db --user=$db_ma --password=$pass_user -e "${sqlCriarUsuario}"
$mysql --host=$db --user=$db_ma --password=$pass_user -e "$sqlCriarDB"
$mysql --host=$db --user=$db_m --password=$pass_user -e "${sqlPermissao1}"
$mysql --host=$db --user=$db_m --password=$pass_user -e "${sqlPermissao2}"
$mysql --host=$db --user=$db_m --password=$pass_user -e "${sqlPermissao3}${sqlFlush}
$mysql --host=$db --user=$db_m --password=$pass_user $dbName < bancoxxx.sql
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'dbUser'@'localhost'
ERROR 1064 (42000) at line 1: 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 ''dbName'.* TO 'dbUser'@'localhost' IDENTIFIED BY 'dbSenha'' at line 1
ERROR 1064 (42000) at line 1: 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 ''dbName'.* TO 'dbUser'@'10.0.%' IDENTIFIED BY 'dbSenha'' at line 1
ERROR 1064 (42000) at line 1: 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 ''dbName'.* TO 'dbUser'@'xxx.xxx.xxx.xx' IDENTIFIED BY 'dbSenha'' at line 1
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'dbName'@'localhost'