mysql命令行中执行sql的几种方式总结
作者:jingxian 时间:2024-01-14 16:11:33
1.直接输入sql执行
MySQL> select now();
+---------------------+
| now() |
+---------------------+
| 2013-09-18 13:55:45 |
+---------------------+
1 row in set (0.00 sec)
2.执行编写好的sql脚本
mysql> source H:/1.sql
+---------------------+
| now() |
+---------------------+
| 2013-09-18 13:54:04 |
+---------------------+
1 row in set (0.00 sec)
3.select ...into outfile 方式执行sql
mysql> select now() into outfile 'h:/data/2.sql';
Query OK, 1 row affected (0.00 sec)
4.使用mysql命令执行
H:\>mysql -uaHmin -p -e "select now()"
Enter passworH: ****
+---------------------+
| now() |
+---------------------+
| 2013-09-18 13:57:09 |
+---------------------+
5.mysql命令执行sql,并将查询结果保存到文本中
a)执行简单sql
mysql -uaHmin -proot test -e "select now()" -N >H:/work/target1.txt
如果sql很长,这种方式就不是很适合了。
b)执行复杂sql
可以将复杂的sql事先编辑好,存放到文本中在执行。
H:\> mysql -uroot -pmypwH -h127.0.0.1 -p3306 test < H:/work/source.sql > H:/work/target.txt
将最后一种执行方式加上操作系统的定时任务,就可以在mysql中实现定时执行sql,并保存执行结果的目的了。
参考:官方文档中的 3.5. Using mysql in Batch Mode
http://dev.mysql.com/doc/refman/5.6/en/batch-mode.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
教你利用python的matplotlib(pyplot)绘制折线图和柱状图
![](https://img.aspxhome.com/file/2023/6/93626_0s.png)
php session 错误
Pycharm远程连接服务器并运行与调试
![](https://img.aspxhome.com/file/2023/0/130960_0s.jpg)
友情连接地址代码-线线表格
如何免费获取 Jetbrain 全家桶使用兑换码的正确姿势(推荐)
![](https://img.aspxhome.com/file/2023/2/117532_0s.jpg)
python使用sklearn实现决策树的方法示例
![](https://img.aspxhome.com/file/2023/8/80408_0s.png)
Python基于分水岭算法解决走迷宫游戏示例
能说明一下GETROWS的用法吗?
python变量命名的7条建议
php记录搜索引擎爬行记录的实现代码
PHP利用header跳转失效的解决方法
SQLServer 跨库查询实现方法
javascript hasFocus使用实例
python3实现磁盘空间监控
Python爬虫库requests获取响应内容、响应状态码、响应头
使用Python-OpenCV向图片添加噪声的实现(高斯噪声、椒盐噪声)
用 Schema 约束 XML 数据
![](https://img.aspxhome.com/file/UploadPic/20108/24/20100814231755976-28s.gif)
详解LyScript 内存扫描与查壳实现
![](https://img.aspxhome.com/file/2023/4/103324_0s.png)
python神经网络Keras实现LSTM及其参数量详解
![](https://img.aspxhome.com/file/2023/1/70701_0s.jpg)