Hi,
I'm trying create script to manage one mysql database, including new db and user creation.
But I'm not able get it working when I put SQL commands into function. So I create simple script for testing which is still not working :-(
Code:
#!/bin/bash -x
MAIN_DIR="/admin/mysql"
MYSQL_CNF="$MAIN_DIR/auth.cnf"
MYSQL_CMD="mysql --defaults-file=$MYSQL_CNF"
create_db_and_user(){
$MYSQL_CMD <<-MYSQLEOF
USE mysql;
CREATE DATABASE testdb;
CREATE USER 'testdb'@'localhost' identified by 'testdb';
FLUSH PRIVILEGES;
QUIT
MYSQLEOF
echo DONE
}
create_db_and_user
Output is following:
Code:
./test.sh
+ MAIN_DIR=/admin/mysql
+ MYSQL_CNF=/admin/mysql/auth.cnf
+ MYSQL_CMD='mysql --defaults-file=/admin/mysql/auth.cnf'
./test.sh: line 22: syntax error: unexpected end of file
Have you any idea why it's not working? Thanks for help