MYSQL 命令行模式下用文件记录所作的操作

本文通过实例演示了如何使用MySQL命令将查询结果导出到文件中。具体操作包括登录MySQL服务器、选择数据库、显示表信息及导出特定表的数据到指定文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql> \T tmp.out

Logging to file 'tmp.out'


mysql> \t

Outfile disabled.

 

 

例子:

 

C:\Users\shiyu>d:


D:\>cd D:\Program Files\xampp\mysql\bin


D:\Program Files\xampp\mysql\bin>mysql -h localhost -u root -p

Enter password: ****


Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 5.0.27-community


Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


mysql> \T tmp.out

Logging to file 'tmp.out'


mysql> use cookbook;

Database changed

mysql> show tables;

+--------------------+

| Tables_in_cookbook |

+--------------------+

| limbs              |

+--------------------+

1 row in set (0.03 sec)


mysql> select * from limbs;

+--------------+------+------+

| thing        | legs | arms |

+--------------+------+------+

| human        |    2 |    2 |

| insect       |    6 |    0 |

| squid        |    0 |   10 |

| octopus      |    0 |    8 |

| fish         |    0 |    0 |

| centipede    |  100 |    0 |

| table        |    4 |    0 |

| armchair     |    4 |    2 |

| phonograph   |    0 |    1 |

| tripod       |    3 |    0 |

| Peg Leg Pete |    1 |    2 |

| space alien  | NULL | NULL |

+--------------+------+------+

12 rows in set (0.04 sec)



'tmp.out'文件打开后的内容:

mysql> use cookbook;

Database changed

mysql> show tables;

+--------------------+

| Tables_in_cookbook |

+--------------------+

| limbs              | 

+--------------------+

1 row in set (0.03 sec)


mysql> select * from limbs;

+--------------+------+------+

| thing        | legs | arms |

+--------------+------+------+

| human        |    2 |    2 | 

| insect       |    6 |    0 | 

| squid        |    0 |   10 | 

| octopus      |    0 |    8 | 

| fish         |    0 |    0 | 

| centipede    |  100 |    0 | 

| table        |    4 |    0 | 

| armchair     |    4 |    2 | 

| phonograph   |    0 |    1 | 

| tripod       |    3 |    0 | 

| Peg Leg Pete |    1 |    2 | 

| space alien  | NULL | NULL | 

+--------------+------+------+

12 rows in set (0.04 sec)



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值