source mysql_test.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
'RROR 1102 (42000): Incorrect database name '
bash: show: command not found...
: command not found...
bash: use: command not found...
: command not found...
-bash: mysql_test.sql: line 5: syntax error near unexpected token `from'
'bash: mysql_test.sql: line 5: `select host,user,authentication_string from user;
脚本内容:
mysql -u root -pXXXXXXX
show databases;
use mysql;
select host,user,authentication_string from user;
show global variables like '%timeout%';
select version();
show variables;
show status;
show table status \G;
netstat -lnpt | grep 3306
cat .mysql_history
cat /etc/my.cnf
进入mysql后逐条执行可以(后三条在系统下执行)。为什么source sql文件就报乱七八糟的错误呢?
看报错应该是database这个参数错误,从脚本内容来看,你并没有指定database这个参数,可能是由于你的脚本格式问题,句末的换行符被解释器认为是一个错误格式。据以往经验,你可能是在windows下编写的文本,直接上传到Linux下边用,导致换行符变成\r,可以尝试把脚本文件用dos2unix转换一下格式。
一般sql脚本可以直接在终端用mysql命令登录之后,直接在mysql cli下source你的sql文件路径。如果你想在bash下非交互式导入,必须用mysql命令配合管道符导入。
参考Zabbix的数据库结构导入命令:
针对你情况:
cat ./mysql_test.sql | mysql -u root -pXXXXXXX