Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 261|回复: 0

[默认分类] MYSQL 连接数据库命令收藏

[复制链接]
  • TA的每日心情
    开心
    2021-12-13 21:45
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    发表于 2018-7-5 16:26:53 | 显示全部楼层 |阅读模式
    一、MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
    1. C:\>mysql -h localhost -u root -p123
    复制代码
    二、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”
    1. C:\>mysql -h 172.16.16.45 -P 3306 -u root -p123
    复制代码
    三、MySQL 连接本地数据库,用户名为“root”,隐藏密码
    1. C:\>mysql -h localhost -u root -p
    2. Enter password:
    复制代码
    四、MySQL 连接本地数据库,用户名为“root”,指定所连接的数据库为“test”
    1. C:\>mysql -h localhost -u root -p123 -D test
    2. mysql>select database();
    3. +------------+
    4. | database() |
    5. +------------+
    6. | test       |
    7. +------------+
    复制代码
    下面是 MySQL 客户端命令的详细参数:
    1. mysql  Ver 14.12 Distrib 5.0.41, for Win32 (ia32)
    2. Copyright (C) 2002 MySQL AB
    3. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
    4. and you are welcome to modify and redistribute it under the GPL license
    5. Usage: mysql [OPTIONS] [database]
    6. -?, --help          Display this help and exit.
    7. -I, --help          Synonym for -?
    8. --auto-rehash       Enable automatic rehashing. One doesn"t need to use
    9. "rehash" to get table and field completion, but startup
    10. and reconnecting may take a longer time. Disable with
    11. --disable-auto-rehash.
    12. -A, --no-auto-rehash
    13. No automatic rehashing. One has to use "rehash" to get
    14. table and field completion. This gives a quicker start of
    15. mysql and disables rehashing on reconnect. WARNING:
    16. options deprecated; use --disable-auto-rehash instead.
    17. -B, --batch         Don"t use history file. Disable interactive behavior.
    18. (Enables --silent)
    19. --character-sets-dir=name
    20. Directory where character sets are.
    21. --default-character-set=name
    22. Set the default character set.
    23. -C, --compress      Use compression in server/client protocol.
    24. -#, --debug[=#]     This is a non-debug version. Catch this and exit
    25. -D, --database=name Database to use.
    26. --delimiter=name    Delimiter to be used.
    27. -e, --execute=name  Execute command and quit. (Disables --force and history
    28. file)
    29. -E, --vertical      Print the output of a query (rows) vertically.
    30. -f, --force         Continue even if we get an sql error.
    31. -G, --named-commands
    32. Enable named commands. Named commands mean this program"s
    33. internal commands; see mysql> help . When enabled, the
    34. named commands can be used from any line of the query,
    35. otherwise only from the first line, before an enter.
    36. Disable with --disable-named-commands. This option is
    37. disabled by default.
    38. -g, --no-named-commands
    39. Named commands are disabled. Use \* form only, or use
    40. named commands only in the beginning of a line ending
    41. with a semicolon (;) Since version 10.9 the client now
    42. starts with this option ENABLED by default! Disable with
    43. "-G". Long format commands still work from the first
    44. line. WARNING: option deprecated; use
    45. --disable-named-commands instead.
    46. -i, --ignore-spaces Ignore space after function names.
    47. --local-infile      Enable/disable LOAD DATA LOCAL INFILE.
    48. -b, --no-beep       Turn off beep on error.
    49. -h, --host=name     Connect to host.
    50. -H, --html          Produce HTML output.
    51. -X, --xml           Produce XML output
    52. --line-numbers      Write line numbers for errors.
    53. -L, --skip-line-numbers
    54. Don"t write line number for errors. WARNING: -L is
    55. deprecated, use long version of this option instead.
    56. -n, --unbuffered    Flush buffer after each query.
    57. --column-names      Write column names in results.
    58. -N, --skip-column-names
    59. Don"t write column names in results. WARNING: -N is
    60. deprecated, use long version of this options instead.
    61. -O, --set-variable=name
    62. Change the value of a variable. Please note that this
    63. option is deprecated; you can set variables directly with
    64. --variable-name=value.
    65. --sigint-ignore     Ignore SIGINT (CTRL-C)
    66. -o, --one-database  Only update the default database. This is useful for
    67. skipping updates to other database in the update log.
    68. -p, --password[=name]
    69. Password to use when connecting to server. If password is
    70. not given it"s asked from the tty.
    71. -W, --pipe          Use named pipes to connect to server.
    72. -P, --port=#        Port number to use for connection.
    73. --prompt=name       Set the mysql prompt to this value.
    74. --protocol=name     The protocol of connection (tcp,socket,pipe,memory).
    75. -q, --quick         Don"t cache result, print it row by row. This may slow
    76. down the server if the output is suspended. Doesn"t use
    77. history file.
    78. -r, --raw           Write fields without conversion. Used with --batch.
    79. --reconnect         Reconnect if the connection is lost. Disable with
    80. --disable-reconnect. This option is enabled by default.
    81. -s, --silent        Be more silent. Print results with a tab as separator,
    82. each row on new line.
    83. --shared-memory-base-name=name
    84. Base name of shared memory.
    85. -S, --socket=name   Socket file to use for connection.
    86. --ssl               Enable SSL for connection (automatically enabled with
    87. other flags). Disable with --skip-ssl.
    88. --ssl-ca=name       CA file in PEM format (check OpenSSL docs, implies
    89. --ssl).
    90. --ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
    91. --ssl-cert=name     X509 cert in PEM format (implies --ssl).
    92. --ssl-cipher=name   SSL cipher to use (implies --ssl).
    93. --ssl-key=name      X509 key in PEM format (implies --ssl).
    94. --ssl-verify-server-cert
    95. Verify server"s "Common Name" in its cert against
    96. hostname used when connecting. This option is disabled by
    97. default.
    98. -t, --table         Output in table format.
    99. -T, --debug-info    Print some debug info at exit.
    100. --tee=name          Append everything into outfile. See interactive help (\h)
    101. also. Does not work in batch mode. Disable with
    102. --disable-tee. This option is disabled by default.
    103. --no-tee            Disable outfile. See interactive help (\h) also. WARNING:
    104. option deprecated; use --disable-tee instead
    105. -u, --user=name     User for login if not current user.
    106. -U, --safe-updates  Only allow UPDATE and DELETE that uses keys.
    107. -U, --i-am-a-dummy  Synonym for option --safe-updates, -U.
    108. -v, --verbose       Write more. (-v -v -v gives the table output format).
    109. -V, --version       Output version information and exit.
    110. -w, --wait          Wait and retry if connection is down.
    111. --connect_timeout=# Number of seconds before connection timeout.
    112. --max_allowed_packet=#
    113. Max packet length to send to, or receive from server
    114. --net_buffer_length=#
    115. Buffer for TCP/IP and socket communication
    116. --select_limit=#    Automatic limit for SELECT when using --safe-updates
    117. --max_join_size=#   Automatic limit for rows in a join when using
    118. --safe-updates
    119. --secure-auth       Refuse client connecting to server if it uses old
    120. (pre-4.1.1) protocol
    121. --show-warnings     Show warnings after every statement.
    122. Default options are read from the following files in the given order:
    123. C:\my.ini C:\my.cnf C:\WINDOWS\my.ini C:\WINDOWS\my.cnf D:\MySQL\my.ini D:\MySQL\my.cnf
    124. The following groups are read: mysql client
    125. The following options may be given as the first argument:
    126. --print-defaults Print the program argument list and exit
    127. --no-defaults  Do not read default options from any options file
    128. --defaults-file=# Only read default options from the given file #
    129. --defaults-extra-file=# Read this file after the global files are read
    130. Variables (--variable-name=value)
    131. and boolean options {FALSE|TRUE}  Value (after reading options)
    132. --------------------------------- -----------------------------
    133. auto-rehash                       TRUE
    134. character-sets-dir                (No default value)
    135. default-character-set             utf8
    136. compress                          FALSE
    137. database                          (No default value)
    138. delimiter                         ;
    139. vertical                          FALSE
    140. force                             FALSE
    141. named-commands                    FALSE
    142. local-infile                      FALSE
    143. no-beep                           FALSE
    144. host                              (No default value)
    145. html                              FALSE
    146. xml                               FALSE
    147. line-numbers                      TRUE
    148. unbuffered                        FALSE
    149. column-names                      TRUE
    150. sigint-ignore                     FALSE
    151. port                              3306
    152. prompt                            mysql>
    153. quick                             FALSE
    154. raw                               FALSE
    155. reconnect                         TRUE
    156. shared-memory-base-name           (No default value)
    157. socket                            (No default value)
    158. ssl                               FALSE
    159. ssl-ca                            (No default value)
    160. ssl-capath                        (No default value)
    161. ssl-cert                          (No default value)
    162. ssl-cipher                        (No default value)
    163. ssl-key                           (No default value)
    164. ssl-verify-server-cert            FALSE
    165. table                             FALSE
    166. debug-info                        FALSE
    167. user                              (No default value)
    168. safe-updates                      FALSE
    169. i-am-a-dummy                      FALSE
    170. connect_timeout                   0
    171. max_allowed_packet                16777216
    172. net_buffer_length                 16384
    173. select_limit                      1000
    174. max_join_size                     1000000
    175. secure-auth                       FALSE
    176. show-warnings                     FALSE
    复制代码
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-2-24 05:17 , Processed in 0.296993 second(s), 36 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表