carlarogers
Member
I cannot understand this behavior that comes up at the end of a sequence that makes sense until this happens. The server seems to assign a value from no where.
I know this looks like a lot of stuff, but it is pretty simple. I am forming commands, putting them into a file to run, but then a value shows up from now where , as if I entered the name of a zipped file for a db instead of just the db name.
Debian 10 web server, with LAMP. My goal is to make a script to load databases and create the user accounts that goes with them, to save time and improve accuracy. I work in an environment that allows one and only one account per mysql (mareiadb) database. So we give the account and the DB the same name to keep it simploer.
Starting with a db dump from another server, delivered to me in gzip format.
That db dump comes in as dadc.sql.gz Here is my script. It all runs great until the very end.
I am really wracking my brain on this one.
Thank you for taking a look,
I know this looks like a lot of stuff, but it is pretty simple. I am forming commands, putting them into a file to run, but then a value shows up from now where , as if I entered the name of a zipped file for a db instead of just the db name.
Debian 10 web server, with LAMP. My goal is to make a script to load databases and create the user accounts that goes with them, to save time and improve accuracy. I work in an environment that allows one and only one account per mysql (mareiadb) database. So we give the account and the DB the same name to keep it simploer.
Starting with a db dump from another server, delivered to me in gzip format.
That db dump comes in as dadc.sql.gz Here is my script. It all runs great until the very end.
Code:
#To run this script, enter
#load_rm 'dbname' 'password' name of the db is the one t comes with. Password is up to you
# formulate commands to run in mariadb or mysql, put the commands into a file,
# then submit the file for processing
zcmd_file="sql.sql"
rm $zcmd_file #delete old files from previous runs if they are not already deleted.
zcall_mysql="mysql -u admin -p`cat /home/carla/db/password`" #admin password saved in my home directory at db/password
zcmd="drop database if exists "${1}";"
echo $zcmd > $zcmd_file #now the first command is in a file that can be submitted with bash
zcmd="CREATE DATABASE "$1" CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
echo $zcmd >> $zcmd_file #2nd command loaded to file
$zcall_mysql < $zcmd_file # this submits the file to mysql/mariadb and its commands process as expected
# next line unzips the db and loads it into the new, empty database created n the previous steps.
gunzip < ${1}.sql.gz | $zcall_mysql $1
# so far so good
zcmd="DROP USER IF EXISTS "$1
echo $zcmd > $zcmd_file # start loading the rest of the commands into the file. Using one > causes the file to be blanked out before loading new commands.
zcmd="DROP USER IF EXISTS "$1
echo $zcmd > $zcmd_file # start loading the rest of the commands into the file. Using one > causes the file to be blanked out before loading new commands.
$zcall_mysql < $zcmd_file # run one command, due to problem about to show up
zcmd="create USER '"${1}"'@'localhost' IDENTIFIED BY '"${2}"';"
echo $zcmd > $zcmd_file # runs ok
$zcall_mysql < $zcmd_file # run one command, due to problem about to show up
#This is where it starts acting like there is something wrong with my computer.
zcmd="GRANT ALL PRIVILEGES ON "$1".* TO '"${1}"'@'localhost' WITH GRANT OPTION;"
echo $zcmd > $zcmd_file
$zcall_mysql < $zcmd_file # run the command.....and the system says:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.gz TO 'dadc'@'localhost' WITH GRANT OPTION' at line 1
.gz??? Where is that coming from? Looking in the file with the command that bombed:
GRANT ALL PRIVILEGES ON dadc.sql.gz TO 'dadc'@'localhost' WITH GRANT OPTION;
I cannot figure out where that dadc.sql.gz is getting in there. To run the commands,I am always entering it like tis
load_rm 'dadc' 'password'
For a reason I do not have any knowledge of, where the script says to use the value of the first parameter ($1), it is putting in the name of archive file.
I am really wracking my brain on this one.
Thank you for taking a look,