shell脚本里如何执行mysql命令 mysql-uroot-p123456 mysql-e\"show tables;
mysql是否有触发机制,可以执行shell脚本 1、将SQL语句直接嵌入到shell脚本文件中复制代码 代码如下:演示环境[root@SZDB~]#more/etc/issueCentOS release 5.9(Final)Kernel \\r on an \\mroot@localhost[(none)]>;show variables like 'version';Variable_name|Value|version|5.6.12-log|[root@SZDB~]#more shell_call_sql1.shbin/bashDefine logTIMESTAMP=`date+Y%m%d%H%M%S`LOG=call_sql_${TIMESTAMP}.logecho\"Start execute sql statement at `date`.\">;>;${LOG}execute sql statmysql-uroot-p123456-etee/tmp/temp.logdrop database if exists tempdb;create database tempdb;use tempdbcreate table if not exists tb_tmp(id smallint,val varchar(20));insert into tb_tmp values(1,'jack'),(2,'robin'),(3,'mark');select*from tb_tmp;noteequitecho-e\"\\n\">;>;${LOG}echo\"below is output result.\">;>;${LOG}cat/tmp/temp.log>;>;${LOG}echo\"script executed successful.\">;>;${LOG}exit;[root@SZDB~]#./shell_call_sql1.shLogging to file '/tmp/temp.log'id|val|1|jack|2|robin|3|mark|Outfile disabled.2、命令行调用单独的SQL文件复制代码 代码如下:[root@SZDB~]#more temp。.
如何用shell脚本实现mysql数据库的操作 直接使用mysql client命令就可以了。如:mysql-u root-p password-h localhost-e\"SQL;