1.mysql -hhostname -uuser -ppsword -e "mysql_cmd"
2.
mysql -hhostname -uuser -ppsword << EOF
mysql_cmd
EOF
如下简单例子:
#!/bin/bash
mysql -hservicedb-online -uroot -proot123 -e "use test;select * from tests;" #方法1实例
mysql -hservicedb-online -uroot -proot123 << EOF #方法2实例
use test;
select * tests;
EOF
本文介绍了两种使用MySQL命令行客户端远程执行SQL命令的方法。第一种方法利用-e选项直接执行SQL命令;第二种方法采用here document方式输入多行SQL命令。通过具体示例展示了如何连接远程数据库并执行SQL查询。
1996

被折叠的 条评论
为什么被折叠?



