I have create a shell script to automate my database migration from host to host, that extracts my Multi WordPress site tables into separated sql
files, so I can decide what site I will migrate each time.
So in my shell script I have the following code:
schema="internet-safe"
PROJECT_FOLDER_NAME="internet-safe"
vagrant_export_folder="/var/www/projects/${PROJECT_FOLDER_NAME}/database/tmp"
query="mysql -uroot -proot -e "SELECT blog_id AS ID, path AS Slug FROM ${schema}.wp_blogs "
query="$query INTO OUTFILE '$vagrant_export_folder/blogs.csv' "
query="$query FIELDS TERMINATED BY ',' "
query="$query ENCLOSED BY '"' "
query="$query LINES TERMINATED BY '
' " > /dev/null"
vagrant ssh --command "cd $vagrant_export_folder && $query"
But by executing this script I get the following error:
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 '-safe.wp_blogs INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs' at line 1
Connection to 127.0.0.1 closed.
An the problem is the dash in the schema name internet-safe
. Is there a way to correct this issue ?
I know that there is an option, to just rename the schema, but, unfortunately I run on unstable vagrant, on xUbuntu, that has destroy my database several times, while I try to provision modifications in my databases.
I also have try the following combinations but I get error messages like the following:
`${schema}`.`wp_blogs`
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 'INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs.csv' FIELDS TE' at line 1
`${schema}`.wp_blogs
ERROR 1046 (3D000) at line 1: No database selected
`${schema}.wp_blogs`
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 'INTO OUTFILE '/var/www/projects/internet-safe/database/tmp/blogs.csv' FIELDS TE' at line 1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…