我正在尝试编写一个小bash脚本,创建一些mysql表,然后分配给一个新用户:
[...]
DBUser='UserA'
VarA='BlaA'
VarB='BlaB'
VarC='BlaC'
[...]
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin <<MYSQL_SCRIPT
create database `${VarA}` character set = 'utf8';
create database `${VarB}` character set = 'utf8';
create database `${VarC}` character set = 'utf8';
create user 'seafile'@'localhost' identified by '${DBUser}';
SET PASSWORD FOR '${DBUser}'@'localhost' = '${dbpw}';
GRANT ALL PRIVILEGES ON `${VarA}`.* to `${DBUser}`@localhost;
GRANT ALL PRIVILEGES ON `${VarB}`.* to `${DBUser}`@localhost;
GRANT ALL PRIVILEGES ON `${VarC}`.* to `${DBUser}`@localhost;
MYSQL_SCRIPT
[...]
目前的结果是:
testinstall: line 93: BlaA: command not found
testinstall: line 93: BlaB: command not found
testinstall: line 93: BlaC: command not found
testinstall: line 93: BlaA: command not found
testinstall: line 93: BlaB: command not found
testinstall: line 93: BlaC: command not found
testinstall: line 93: UserA: command not found
testinstall: line 93: BlaC: command not found
testinstall: line 93: UserA: command not found
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 'character set = 'utf8'' at line 1
如何正确设置mysql\u脚本部分以使用变量?
编辑:谢谢@andrewbone谢谢,命令的问题没有发现,删除了“`”。现在我仍然有“character set='utf8'的问题”
# create database ${VarA} character set = 'utf8';
# 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 '-db character set = utf8' at line 1
如果我直接在mysql上运行它:
create database `bla1` character set = 'utf8';
# Query OK, 1 row affected (0.00 sec)
有什么办法解决吗?
谢谢您。
暂无答案!
目前还没有任何答案,快来回答吧!