继续上一篇的话题,介绍mysql命令行的一些小技巧。
1.以html格式输出结果
使用mysql客户端的参数–html或者-T,则所有SQL的查询结果会自动生成为html的table代码
$ mysql -uroot --html Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3286 Server version: 5.1.24-rc-log MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> select * from test.test; <TABLE BORDER=1><TR><TH>i</TH></TR><TR><TD>1</TD></TR><TR><TD>2</TD></TR></TABLE> 2 rows in set (0.00 sec)
2.以xml格式输出结果
跟上面差不多,使用–xml或者-X选项,可以将结果输出为xml格式
$ mysql -uroot --xml
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3287
Server version: 5.1.24-rc-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select * from test.test;
<?xml version="1.0"?>
<resultset statement="select * from test.test;"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="i">1</field>
</row>
<row>
<field name="i">2</field>
</row>
</resultset>
2 rows in set (0.00 sec)
3.修改命令提示符
使用mysql的–prompt=选项,或者进入mysql命令行环境后使用prompt命令,都可以修改提示符
mysql> prompt \u@\d> PROMPT set to '\u@\d>' root@(none)>use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed root@mysql>
其中\u表示当前连接的用户,\d表示当前连接的数据库,其他更多的可选项可以参考man mysql
[…] MySQL命令行的几个用法(续)MySQL命令行的几个用法缓存为王:Memcached和MySQL的结合应用MySQL如何获取当前执行的SQL用HSCALE实现MySQL的数据分布式存储卸载rpm包遭遇error: specifies multiple packages […]