1. 程式人生 > >mysql命令常用參數實例講解

mysql命令常用參數實例講解

mysql

mysql命令常用參數實例講解



以下是mysql命令常用的參數,配合實例進行簡單講解

1auto-rehash自動補全(表名及表中字段)
---------------------------------------
[mysql]
#no-auto-rehash
auto-rehash
---------------------------------------
mysql -u root --auto-rehash
---------------------------------------

1. mysql> use test

2. Database changed

3.

mysql> select acc //這裏自動補全,只是提示表名,和表裏面的字段名,不像php可以提示函數名

4. account account.acct_num account.amount acct_num

2,-B 不要使用歷史記錄文件。禁用交互式行為。

1. [root@cheng]# mysql -uroot -D bak_test -e "show tables;" -B

2. Tables_in_bak_test

3. comment

4. user

3,-E 垂直打印查詢 () 的輸出。

1.

[root@cheng]# mysql -uroot bak_test -e "show tables;" -E

2. *************************** 1. row ***************************

3. Tables_in_bak_test: comment

4. *************************** 2. row ***************************

5. Tables_in_bak_test: user

4,-D 指定進入的庫

1. [root@Cheng]# mysql -u root -D test

進入後默認就在test數據庫裏面,不用use test;

5--default-character-set設置默認字符集

1. [root@Cheng]# mysql -u root -D test --default-character-set=utf8

6--delimiter設置mysql命令結束符

1. [root@Cheng]# mysql -u root -D test --delimiter=\|

mysql默認的命令結束符是分號,現在把它設置成豎杠,要註意|前面的\

7-e 執行sql語句

1. [root@cheng]# mysql -uroot -D bak_test -e "show tables;"

8-f的用法

1. [root@cheng]# mysql -uroot bak_test -e "show databaseds;show tables;" -

2. f

3. ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the ma

4. nual that corresponds to your MySQL server version for the right syntax to use n

5. ear 'databaseds' at line 1

6. +--------------------+

7. | Tables_in_bak_test |

8. +--------------------+

9. | comment |

10. | user |

11. +--------------------+

忽略mysql的錯誤,繼續向下執行

9-N 不顯示列名

1. [root@cheng]# mysql -uroot bak_test -e "select * from user" -N

2. +---+------+---+

3. | 1 | bb | 0 |

4. | 2 | tank | 0 |

5. +---+------+---+

10-p 使用密碼登陸

1. [root@Cheng]# mysql -u root -o test -p -S /tmp/mysql.sock

2. Enter password

11-h指定登陸的主機IP

1. [root@Cheng]# mysql -u root -h 192.168.1.102

12-H 生成 HTML 輸出。

1. [root@cheng]# mysql -uroot bak_test -e "show tables " -H

2. <TABLE BORDER=1><TR><TH>Tables_in_bak_test</TH></TR><TR><TD>comment</TD></TR><TR

3. ><TD>user</TD></TR></TABLE>

13-X 生成XML輸出。

1. [root@cheng]# mysql -uroot bak_test -e "show tables " -X

2. <?xml version="1.0"?>

3.

4. <resultset statement="show tables

5. " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

6. <row>

7. <field name="Tables_in_bak_test">comment</field>

8. </row>

9.

10. <row>

11. <field name="Tables_in_bak_test">user</field>

12. </row>

13. </resultset>

14--prompt 設置mysql提示符

1. [root@Cheng]# mysql -u root --prompt=\^\_\^

2. ^_^show databases;

3. +--------------------+

4. | Database |

5. +--------------------+

6. | information_schema |

7. | biztojie |

mysql的提示符,我把它設置成笑臉了。

15-S 指定登陸用的socket

1. [root@Cheng]# mysql -u root -D test -S /tmp/mysql.sock

當我們一臺服務器啟動了二個不同mysql版本的時候,存放socket的文件是不能一樣的,-S用來指定連接到那個,多實例時常用。

16-v 輸出mysql執行的語句。

1. [root@Cheng]# mysql -u root -D test -e "show tables;" -v

2. --------------

3. show tables

4. --------------

17-P指定端口

1. [root@Cheng]# mysql -u root -o test -P 13306 -S /tmp/mysql.sock


mysql命令常用參數實例講解