`
Flory
  • 浏览: 24729 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

MYSQL 连接数据库命令收藏

阅读更多
一、MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
C:\>mysql -h localhost -u root -p123
二、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”
C:\>mysql -h 172.16.16.45 -P 3306 -u root -p123
三、MySQL 连接本地数据库,用户名为“root”,隐藏密码
C:\>mysql -h localhost -u root -p
Enter password:
四、MySQL 连接本地数据库,用户名为“root”,指定所连接的数据库为“test”
C:\>mysql -h localhost -u root -p123 -D test
mysql>select database();
+------------+
| database() |
+------------+
| test       |
+------------+
下面是 MySQL 客户端命令的详细参数:
mysql  Ver 14.12 Distrib 5.0.41, for Win32 (ia32)
Copyright (C) 2002 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Usage: mysql [OPTIONS] [database]
-?, --help          Display this help and exit.
-I, --help          Synonym for -?
--auto-rehash       Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
-A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get
table and field completion. This gives a quicker start of
mysql and disables rehashing on reconnect. WARNING:
options deprecated; use --disable-auto-rehash instead.
-B, --batch         Don't use history file. Disable interactive behavior.
(Enables --silent)
--character-sets-dir=name
Directory where character sets are.
--default-character-set=name
Set the default character set.
-C, --compress      Use compression in server/client protocol.
-#, --debug[=#]     This is a non-debug version. Catch this and exit
-D, --database=name Database to use.
--delimiter=name    Delimiter to be used.
-e, --execute=name  Execute command and quit. (Disables --force and history
file)
-E, --vertical      Print the output of a query (rows) vertically.
-f, --force         Continue even if we get an sql error.
-G, --named-commands
Enable named commands. Named commands mean this program's
internal commands; see mysql> help . When enabled, the
named commands can be used from any line of the query,
otherwise only from the first line, before an enter.
Disable with --disable-named-commands. This option is
disabled by default.
-g, --no-named-commands
Named commands are disabled. Use \* form only, or use
named commands only in the beginning of a line ending
with a semicolon (;) Since version 10.9 the client now
starts with this option ENABLED by default! Disable with
'-G'. Long format commands still work from the first
line. WARNING: option deprecated; use
--disable-named-commands instead.
-i, --ignore-spaces Ignore space after function names.
--local-infile      Enable/disable LOAD DATA LOCAL INFILE.
-b, --no-beep       Turn off beep on error.
-h, --host=name     Connect to host.
-H, --html          Produce HTML output.
-X, --xml           Produce XML output
--line-numbers      Write line numbers for errors.
-L, --skip-line-numbers
Don't write line number for errors. WARNING: -L is
deprecated, use long version of this option instead.
-n, --unbuffered    Flush buffer after each query.
--column-names      Write column names in results.
-N, --skip-column-names
Don't write column names in results. WARNING: -N is
deprecated, use long version of this options instead.
-O, --set-variable=name
Change the value of a variable. Please note that this
option is deprecated; you can set variables directly with
--variable-name=value.
--sigint-ignore     Ignore SIGINT (CTRL-C)
-o, --one-database  Only update the default database. This is useful for
skipping updates to other database in the update log.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-W, --pipe          Use named pipes to connect to server.
-P, --port=#        Port number to use for connection.
--prompt=name       Set the mysql prompt to this value.
--protocol=name     The protocol of connection (tcp,socket,pipe,memory).
-q, --quick         Don't cache result, print it row by row. This may slow
down the server if the output is suspended. Doesn't use
history file.
-r, --raw           Write fields without conversion. Used with --batch.
--reconnect         Reconnect if the connection is lost. Disable with
--disable-reconnect. This option is enabled by default.
-s, --silent        Be more silent. Print results with a tab as separator,
each row on new line.
--shared-memory-base-name=name
Base name of shared memory.
-S, --socket=name   Socket file to use for connection.
--ssl               Enable SSL for connection (automatically enabled with
other flags). Disable with --skip-ssl.
--ssl-ca=name       CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name     X509 cert in PEM format (implies --ssl).
--ssl-cipher=name   SSL cipher to use (implies --ssl).
--ssl-key=name      X509 key in PEM format (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-t, --table         Output in table format.
-T, --debug-info    Print some debug info at exit.
--tee=name          Append everything into outfile. See interactive help (\h)
also. Does not work in batch mode. Disable with
--disable-tee. This option is disabled by default.
--no-tee            Disable outfile. See interactive help (\h) also. WARNING:
option deprecated; use --disable-tee instead
-u, --user=name     User for login if not current user.
-U, --safe-updates  Only allow UPDATE and DELETE that uses keys.
-U, --i-am-a-dummy  Synonym for option --safe-updates, -U.
-v, --verbose       Write more. (-v -v -v gives the table output format).
-V, --version       Output version information and exit.
-w, --wait          Wait and retry if connection is down.
--connect_timeout=# Number of seconds before connection timeout.
--max_allowed_packet=#
Max packet length to send to, or receive from server
--net_buffer_length=#
Buffer for TCP/IP and socket communication
--select_limit=#    Automatic limit for SELECT when using --safe-updates
--max_join_size=#   Automatic limit for rows in a join when using
--safe-updates
--secure-auth       Refuse client connecting to server if it uses old
(pre-4.1.1) protocol
--show-warnings     Show warnings after every statement.

Default options are read from the following files in the given order:
C:\my.ini C:\my.cnf C:\WINDOWS\my.ini C:\WINDOWS\my.cnf D:\MySQL\my.ini D:\MySQL\my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit
--no-defaults  Do not read default options from any options file
--defaults-file=# Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- -----------------------------
auto-rehash                       TRUE
character-sets-dir                (No default value)
default-character-set             utf8
compress                          FALSE
database                          (No default value)
delimiter                         ;
vertical                          FALSE
force                             FALSE
named-commands                    FALSE
local-infile                      FALSE
no-beep                           FALSE
host                              (No default value)
html                              FALSE
xml                               FALSE
line-numbers                      TRUE
unbuffered                        FALSE
column-names                      TRUE
sigint-ignore                     FALSE
port                              3306
prompt                            mysql>
quick                             FALSE
raw                               FALSE
reconnect                         TRUE
shared-memory-base-name           (No default value)
socket                            (No default value)
ssl                               FALSE
ssl-ca                            (No default value)
ssl-capath                        (No default value)
ssl-cert                          (No default value)
ssl-cipher                        (No default value)
ssl-key                           (No default value)
ssl-verify-server-cert            FALSE
table                             FALSE
debug-info                        FALSE
user                              (No default value)
safe-updates                      FALSE
i-am-a-dummy                      FALSE
connect_timeout                   0
max_allowed_packet                16777216
net_buffer_length                 16384
select_limit                      1000
max_join_size                     1000000
secure-auth                       FALSE
show-warnings                     FALSE



分类: 数据库
分享到:
评论

相关推荐

    mysql数据库cmd命令大全

    本文档总结了 MySQL 数据库 cmd 命令的使用方法和实践经验,涵盖了连接数据库、授权、数据库操作、表操作、字段类型、修改密码、备份数据库、数据库导入和导出、表索引等方面的知识点。 连接数据库 1. 本地连接 ...

    mysql数据库常用命令汇总

    1. 数据库验证连接:使用mysql.exe命令连接到数据库,需要指定主机地址、端口号、用户名和密码,例如:`mysql.exe -h localhost -P3306 -u root -p` 2. 创建数据库:使用`create database`命令创建一个新的数据库,...

    最全Mysql数据库命令

    4. **连接数据库**: ``` use 数据库名; ``` 5. **查看当前使用的数据库**: ``` select database(); ``` 四、表操作 1. **创建表**: ``` create table 表名 ( 字段名1 类型1, ... 字段名n 类型n ); ...

    连接MYSQL数据库命令

    ### 连接MYSQL数据库命令详解 在日常工作中,我们经常需要与MySQL数据库进行交互,而掌握如何正确地连接到MySQL数据库则是基础中的基础。本文将详细介绍如何通过命令行方式连接到本地或远程的MySQL数据库,并解释...

    MySQL API连接数据库

    - MySQL API主要由一组C语言函数组成,如`mysql_connect`,`mysql_query`等,用于执行SQL命令、处理结果集和管理数据库连接。 - 这些API函数使开发者能够直接与MySQL服务器交互,而无需依赖特定的数据库访问库。 ...

    mysql数据库命令

    ### MySQL数据库命令介绍 #### 1. `mysqld-nt-remove` 该命令用于移除MySQL服务。当您不再需要MySQL服务在系统启动时自动运行或希望重新安装MySQL服务时,可以使用此命令。在命令行中执行`mysqld-nt-remove`后,...

    操作mysql数据库的常用命令总结

    以下是一些关于操作MySQL数据库的常用命令的详细说明: 1. **连接MySQL**:使用`mysql -u 用户名 -p`命令可以连接到MySQL服务器,其中`-u`指定用户名,`-p`会提示输入密码。例如,连接名为root的用户,命令是`mysql...

    Android 实现连接MySQL数据库

    本文将详细讲解如何在Android中实现连接到MySQL数据库,以及相关的技术要点。 首先,理解基本概念:Android是运行在移动设备上的操作系统,而MySQL是服务器端的关系型数据库管理系统。由于Android设备通常不能直接...

    linux下QT连接mysql数据库.doc

    QT 连接 MySQL 数据库在 Linux 平台下的实现 在 Linux 平台下,使用 QT 连接 MySQL 数据库是一种常见的应用场景。本文将详细介绍如何使用 QT 连接 MySQL 数据库,并提供了相关的代码示例。 首先,需要安装 MySQL ...

    VB6连接MySQL数据库实例含驱动和源代码

    总的来说,VB6连接MySQL数据库实例为初学者提供了一个直观的起点,帮助他们理解和实践数据库连接、SQL命令执行、数据读取等基本概念。通过学习这个实例,开发者将能够创建自己的VB6应用程序,与MySQL数据库进行有效...

    C# 连接mysql数据库

    在提供的信息中提到了"MySQLDriverCS.dll",这是一个用于.NET的MySQL连接器,它使得C#能够通过ODBC或ADO.NET接口与MySQL通信。安装这个驱动后,我们就可以在C#项目中引用它,以便进行数据库操作。 以下是使用C#连接...

    命令窗口创建mysql数据库

    【MySQL数据库连接与管理】...以上就是关于通过命令窗口创建MySQL数据库以及进行数据库管理的相关知识点,包括连接、密码修改、数据库创建和基本的SQL操作。通过熟练掌握这些命令,你可以高效地管理和操作MySQL数据库。

    连接mysql数据库

    下面以Python为例,展示如何使用`pymysql`库连接数据库: ```python import pymysql # 创建连接 conn = pymysql.connect(host='localhost', user='root', password='your_password', db='your_database', charset=...

    MySQL数据库常用命令大全.pdf

    根据提供的文件信息,本文将对MySQL数据库的连接方式、密码管理、用户添加及数据库操作等几个方面进行详细解析,帮助读者更好地理解和掌握这些基础而重要的MySQL命令。 ### 一、连接MySQL #### 1. 连接到本地MySQL...

    mysql5.0 数据库命令实例

    ### MySQL 5.0 数据库命令实例解析 #### 连接 MySQL 在使用 MySQL 数据库进行操作之前,首要任务就是连接数据库。以下是连接 MySQL 的基本命令格式及其具体应用实例。 ##### 格式 ``` mysql -h 主机地址 -u ...

    Qt连接Mysql数据库驱动

    在进行Qt与MySQL数据库连接之前,首先需要了解如何搭建开发环境以及如何编译Qt与MySQL数据库之间的驱动。下面详细介绍如何分步骤搭建Qt开发环境、MySQL数据库环境,并编译Qt连接MySQL数据库驱动。 1. Qt开发环境...

    C#连接Mysql数据库的DLL

    3. **连接数据库**: 连接MySQL数据库的关键类是`MySqlConnection`,它是`MySql.Data.MySqlClient`命名空间的一部分。以下是一个简单的示例代码,展示如何创建数据库连接: ```csharp using MySql.Data....

    mysql常用数据库命令[参考].pdf

    MySQL是当前最流行的开源关系数据库管理系统之一,本文详细介绍了MySQL常用数据库命令,包括连接MySQL、修改密码、增加新用户、操作技巧、显示命令、建库、建表、插入数据等方面的知识点。 一、连接MYSQL 连接...

    C#连接MySQL数据库代码示例

    在C#项目中,我们需要添加对`MySql.Data` NuGet包的引用,它包含了MySQL连接所需的组件。 连接数据库的关键在于创建一个` MySqlConnection `对象,该对象是`MySql.Data.MySqlClient`命名空间下的类。连接字符串通常...

Global site tag (gtag.js) - Google Analytics