MYSQL基础:mysql客户端工具
生活随笔
收集整理的這篇文章主要介紹了
MYSQL基础:mysql客户端工具
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
關(guān)于mysql客戶端工具,和sqlplus一樣通過為用戶提供一個(gè)命令行接口來操作和管理MYSQL服務(wù)器。 本文總結(jié)一下常用的選項(xiàng)和基礎(chǔ)的幾個(gè)設(shè)定技巧。
常用選項(xiàng)
| -e | –execute=name | 執(zhí)行指定命令后退出 |
常用場(chǎng)景:
在腳本后者程序中嵌入使用,不希望使用交互式的方式使用msql客戶端,執(zhí)行一條指定的語句后退出。
使用例:
# mysql -uroot -pliumiaocn -e "desc mysql.time_zone" mysql: [Warning] Using a password on the command line interface can be insecure. +------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+----------------+ | Time_zone_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | Use_leap_seconds | enum('Y','N') | NO | | N | | +------------------+------------------+------+-----+---------+----------------+ #| -E | –vertical | 以縱列方式顯示顯示結(jié)果,類似\G的作用 |
使用例:將見一個(gè)例子以縱列方式顯示
# mysql -uroot -pliumiaocn -E -e "desc mysql.time_zone" mysql: [Warning] Using a password on the command line interface can be insecure. *************************** 1. row ***************************Field: Time_zone_idType: int(10) unsignedNull: NOKey: PRI Default: NULLExtra: auto_increment *************************** 2. row ***************************Field: Use_leap_secondsType: enum('Y','N')Null: NOKey: Default: NExtra: #| -H | –html | 結(jié)果以HTML方式進(jìn)行保存 |
| -X | –xml | 結(jié)果以XML方式進(jìn)行保存 |
常用場(chǎng)景:
以HTML頁面或者XML格式方式將執(zhí)行的過程直接生成HTML文件時(shí)可以使用
使用例:
# mysql -uroot -pliumiaocn -H -e "desc mysql.time_zone" mysql: [Warning] Using a password on the command line interface can be insecure. <TABLE BORDER=1><TR><TH>Field</TH><TH>Type</TH><TH>Null</TH><TH>Key</TH><TH>Default</TH><TH>Extra</TH></TR><TR><TD>Time_zone_id</TD><TD>int(10) unsigned</TD><TD>NO</TD><TD>PRI</TD><TD>NULL</TD><TD>auto_increment</TD></TR><TR><TD>Use_leap_seconds</TD><TD>enum('Y','N')</TD><TD>NO</TD><TD></TD><TD>N</TD><TD></TD></TR></TABLE># #將此輸出的HTML內(nèi)容進(jìn)行保存,用瀏覽器打開,可以看到效果如下所示
| - | –prompt=name | 執(zhí)行提示信息 |
常用場(chǎng)景:
修改默認(rèn)的mysql>的提示信息,同Linux上的prompt一樣,可以用于提示一些具體的特定信息,比如當(dāng)前用戶,使用的數(shù)據(jù)庫(kù)信息,時(shí)間信息等,可以對(duì)操作者進(jìn)行一定的提醒或者警示作用
使用例:將默認(rèn)的mysql提示改成 hello to liumiaocn mysql。
# mysql -uroot -pliumiaocn --prompt="hello to liumiaocn mysql>" mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 45618 Server version: 5.7.16 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.hello to liumiaocn mysql>更常見的使用方式比如如下所示:
# mysql -uroot -pliumiaocn --prompt="[\\u@\\h(\\d) \\R:\\m:\\s] mysql>" mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 47427 Server version: 5.7.16 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.[root@localhost((none)) 17:24:04] mysql>use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed [root@localhost(mysql) 17:24:11] mysql>- 時(shí)間相關(guān)信息
| \D | 完整的日期和時(shí)間 |
| \y | YY格式的年 |
| \Y | YYYY格式的年 |
| \o | 以數(shù)字方式顯示的月份 |
| \O | 以字母方式顯示的月份 |
| \w | 以字母顯示的星期信息 |
| \P | am/pm標(biāo)志 |
| \r | 12小時(shí)制時(shí)間 |
| \R | 24小時(shí)制時(shí)間 |
| \m | 分 |
| \s | 秒 |
- 其他設(shè)定信息
| \u | 當(dāng)前用戶名 |
| \U | 包含主機(jī)名的用戶名 |
| \h | 當(dāng)前主機(jī) |
| \d | 當(dāng)前使用的數(shù)據(jù)庫(kù) |
| \v | 服務(wù)器的版本號(hào) |
| \p | 當(dāng)前端口號(hào)或者socket文件名 |
| \c | 當(dāng)前輸入行數(shù) |
- 特殊字符
| \t | 制表符 |
| \l | 當(dāng)前分隔符 |
| \S | 分號(hào) |
| ’ | 單引號(hào) |
| " | 雙引號(hào) |
| _ | 空格字符 |
| \ | 反斜線 |
| \n | 換行符 |
總結(jié)
以上是生活随笔為你收集整理的MYSQL基础:mysql客户端工具的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三合一剪弦器怎么用_三合一冲锋衣推荐选购
- 下一篇: 再看数据库——(2)视图