xywuyiba8 发表于 2018-9-30 07:40:36

mysql命令常用参数实例讲解

  mysql命令常用参数实例讲解
以下是mysql命令常用的参数,配合实例进行简单讲解  1,auto-rehash自动补全(表名及表中字段)
  ---------------------------------------
  
  #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_numaccount.amount    acct_num
  2,-B 不要使用历史记录文件。禁用交互式行为。
  1.# mysql -uroot -D bak_test -e "show tables;" -B
  2.Tables_in_bak_test
  3.comment
  4.user
  3,-E 垂直打印查询(行) 的输出。
  1.# 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.# mysql -u root -D test
  进入后默认就在test数据库里面,不用use test;
  5,--default-character-set设置默认字符集
  1.   # mysql -u root -D test--default-character-set=utf8
  6,--delimiter设置mysql命令结束符
  1.# mysql -u root -D test   --delimiter=\|
  mysql默认的命令结束符是分号,现在把它设置成竖杠,要注意|前面的\
  7,-e 执行sql语句
  1.   # mysql -uroot -D bak_test -e "show tables;"
  8,-f的用法
  1.   # 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.   # mysql -uroot bak_test -e "select * from user" -N
  2.+---+------+---+
  3.| 1 |   bb | 0 |
  4.| 2 | tank | 0 |
  5.+---+------+---+
  10,-p 使用密码登陆
  1.# mysql -u root -o test -p   -S /tmp/mysql.sock
  2.Enter password
  11,-h指定登陆的主机IP
  1.# mysql -u root -h 192.168.1.102
  12,-H 生成HTML 输出。
  1.# mysql -uroot bak_test -e "show tables" -H
  2.Tables_in_bak_testcommentuser
  13,-X 生成XML输出。
  1.# mysql -uroot bak_test -e "show tables" -X
  2.
  3.
  4.
  6.   
  7.   comment
  8.   
  9.
  10.
  11.user
  12.
  13.
  14,--prompt 设置mysql提示符
  1.# mysql -u root --prompt=\^\_\^
  2.^_^show databases;
  3.+--------------------+
  4.| Database         |
  5.+--------------------+
  6.| information_schema |
  7.| biztojie         |
  mysql的提示符,我把它设置成笑脸了。
  15,-S 指定登陆用的socket
  1.# mysql -u root -D test   -S /tmp/mysql.sock
  当我们一台服务器启动了二个不同mysql版本的时候,存放socket的文件是不能一样的,-S用来指定连接到那个,多实例时常用。
  16,-v 输出mysql执行的语句。
  1.# mysql -u root -D test -e "show tables;"   -v
  2.--------------
  3.show tables
  4.--------------
  17,-P指定端口
  1.# mysql -u root -o test-P 13306-S /tmp/mysql.sock

页: [1]
查看完整版本: mysql命令常用参数实例讲解