一、MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
C:/>mysql -h localhost -u root -p123
二、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”
C:/>mysql -h 192.168.0.201 -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.<