<p>一、MySQL 连接本地数据库,用户名为"root",密码"123"(注意:"-p"和"123" 之间不能有空格)</p><pre class="brush:bash;toolbar:false">C:\>mysql-hlocalhost-uroot-p123</pre><p>二、MySQL 连接远程数据库(192.168.0.201),端口"3306",用户名为"root",密码"123"</p><pre class="brush:bash;toolbar:false">C:\>mysql-h172.16.16.45-P3306-uroot-p123</pre><p>三、MySQL 连接本地数据库,用户名为"root",隐藏密码</p><pre class="brush:bash;toolbar:false">C:\>mysql-hlocalhost-uroot-p</pre><p>Enter password:</p><p>四、MySQL 连接本地数据库,用户名为"root",指定所连接的数据库为"test"</p><pre class="brush:bash;toolbar:false">C:\>mysql-hlocalhost-uroot-p123-Dtest
mysql>selectdatabase();
+------------+
|database()|
+------------+
|test|
+------------+</pre><p>下面是 MySQL 客户端命令的详细参数:</p><pre class="brush:bash;toolbar:false">mysqlVer14.12Distrib5.0.41,forWin32(ia32)
Copyright(C)2002MySQLAB
ThissoftwarecomeswithABSOLUTELYNOWARRANTY.Thisisfreesoftware,
andyouarewelcometomodifyandredistributeitundertheGPLlicense
Usage:mysql[OPTIONS][database]
-?,--helpDisplaythishelpandexit.
-I,--helpSynonymfor-?
--auto-rehashEnableautomaticrehashing.Onedoesn'tneedtouse
'rehash'togettableandfieldcompletion,butstartup
andreconnectingmaytakealongertime.Disablewith
--disable-auto-rehash.
-A,--no-auto-rehash
Noautomaticrehashing.Onehastouse'rehash'toget
tableandfieldcompletion.Thisgivesaquickerstartof
mysqlanddisablesrehashingonreconnect.WARNING:
optionsdeprecated;use--disable-auto-rehashinstead.
-B,--batchDon'tusehistoryfile.Disableinteractivebehavior.
(Enables--silent)
--character-sets-dir=name
Directorywherecharactersetsare.
--default-character-set=name
Setthedefaultcharacterset.
-C,--compressUsecompressioninserver/clientprotocol.
-#,--debug[=#]Thisisanon-debugversion.Catchthisandexit
-D,--database=nameDatabasetouse.
--delimiter=nameDelimitertobeused.
-e,--execute=nameExecutecommandandquit.(Disables--forceandhistory
file)
-E,--verticalPrinttheoutputofaquery(rows)vertically.
-f,--forceContinueevenifwegetansqlerror.
-G,--named-commands
Enablenamedcommands.Namedcommandsmeanthisprogram's
internalcommands;seemysql>help.Whenenabled,the
namedcommandscanbeusedfromanylineofthequery,
otherwiseonlyfromthefirstline,beforeanenter.
Disablewith--disable-named-commands.Thisoptionis
disabledbydefault.
-g,--no-named-commands
Namedcommandsaredisabled.Use\*formonly,oruse
namedcommandsonlyinthebeginningofalineending
withasemicolon(;)Sinceversion10.9theclientnow
startswiththisoptionENABLEDbydefault!Disablewith
'-G'.Longformatcommandsstillworkfromthefirst
line.WARNING:optiondeprecated;use
--disable-named-commandsinstead.
-i,--ignore-spacesIgnorespaceafterfunctionnames.
--local-infileEnable/disableLOADDATALOCALINFILE.
-b,--no-beepTurnoffbeeponerror.
-h,--host=nameConnecttohost.
-H,--htmlProduceHTMLoutput.
-X,--xmlProduceXMLoutput
--line-numbersWritelinenumbersforerrors.
-L,--skip-line-numbers
Don'twritelinenumberforerrors.WARNING:-Lis
deprecated,uselongversionofthisoptioninstead.
-n,--unbufferedFlushbufferaftereachquery.
--column-namesWritecolumnnamesinresults.
-N,--skip-column-names
Don'twritecolumnnamesinresults.WARNING:-Nis
deprecated,uselongversionofthisoptionsinstead.
-O,--set-variable=name
Changethevalueofavariable.Pleasenotethatthis
optionisdeprecated;youcansetvariablesdirectlywith
--variable-name=value.
--sigint-ignoreIgnoreSIGINT(CTRL-C)
-o,--one-databaseOnlyupdatethedefaultdatabase.Thisisusefulfor
skippingupdatestootherdatabaseintheupdatelog.
-p,--password[=name]
Passwordtousewhenconnectingtoserver.Ifpasswordis
notgivenit'saskedfromthetty.
-W,--pipeUsenamedpipestoconnecttoserver.
-P,--port=#Portnumbertouseforconnection.
--prompt=nameSetthemysqlprompttothisvalue.
--protocol=nameTheprotocolofconnection(tcp,socket,pipe,memory).
-q,--quickDon'tcacheresult,printitrowbyrow.Thismayslow
downtheserveriftheoutputissuspended.Doesn'tuse
historyfile.
-r,--rawWritefieldswithoutconversion.Usedwith--batch.
--reconnectReconnectiftheconnectionislost.Disablewith
--disable-reconnect.Thisoptionisenabledbydefault.
-s,--silentBemoresilent.Printresultswithatabasseparator,
eachrowonnewline.
--shared-memory-base-name=name
Basenameofsharedmemory.
-S,--socket=nameSocketfiletouseforconnection.
--sslEnableSSLforconnection(automaticallyenabledwith
otherflags).Disablewith--skip-ssl.
--ssl-ca=nameCAfileinPEMformat(checkOpenSSLdocs,implies
--ssl).
--ssl-capath=nameCAdirectory(checkOpenSSLdocs,implies--ssl).
--ssl-cert=nameX509certinPEMformat(implies--ssl).
--ssl-cipher=nameSSLciphertouse(implies--ssl).
--ssl-key=nameX509keyinPEMformat(implies--ssl).
--ssl-verify-server-cert
Verifyserver's"CommonName"initscertagainst
hostnameusedwhenconnecting.Thisoptionisdisabledby
default.
-t,--tableOutputintableformat.
-T,--debug-infoPrintsomedebuginfoatexit.
--tee=nameAppendeverythingintooutfile.Seeinteractivehelp(\h)
also.Doesnotworkinbatchmode.Disablewith
--disable-tee.Thisoptionisdisabledbydefault.
--no-teeDisableoutfile.Seeinteractivehelp(\h)also.WARNING:
optiondeprecated;use--disable-teeinstead
-u,--user=nameUserforloginifnotcurrentuser.
-U,--safe-updatesOnlyallowUPDATEandDELETEthatuseskeys.
-U,--i-am-a-dummySynonymforoption--safe-updates,-U.
-v,--verboseWritemore.(-v-v-vgivesthetableoutputformat).
-V,--versionOutputversioninformationandexit.
-w,--waitWaitandretryifconnectionisdown.
--connect_timeout=#Numberofsecondsbeforeconnectiontimeout.
--max_allowed_packet=#
Maxpacketlengthtosendto,orreceivefromserver
--net_buffer_length=#
BufferforTCP/IPandsocketcommunication
--select_limit=#AutomaticlimitforSELECTwhenusing--safe-updates
--max_join_size=#Automaticlimitforrowsinajoinwhenusing
--safe-updates
--secure-authRefuseclientconnectingtoserverifitusesold
(pre-4.1.1)protocol
--show-warningsShowwarningsaftereverystatement.
Defaultoptionsarereadfromthefollowingfilesinthegivenorder:
C:\my.iniC:\my.cnfC:\WINDOWS\my.iniC:\WINDOWS\my.cnfD:\MySQL\my.iniD:\MySQL\my.cnf
Thefollowinggroupsareread:mysqlclient
Thefollowingoptionsmaybegivenasthefirstargument:
--print-defaultsPrinttheprogramargumentlistandexit
--no-defaultsDonotreaddefaultoptionsfromanyoptionsfile
--defaults-file=#Onlyreaddefaultoptionsfromthegivenfile#
--defaults-extra-file=#Readthisfileaftertheglobalfilesareread
Variables(--variable-name=value)
andbooleanoptions{FALSE|TRUE}Value(afterreadingoptions)
--------------------------------------------------------------
auto-rehashTRUE
character-sets-dir(Nodefaultvalue)
default-character-setutf8
compressFALSE
database(Nodefaultvalue)
delimiter;
verticalFALSE
forceFALSE
named-commandsFALSE
local-infileFALSE
no-beepFALSE
host(Nodefaultvalue)
htmlFALSE
xmlFALSE
line-numbersTRUE
unbufferedFALSE
column-namesTRUE
sigint-ignoreFALSE
port3306
promptmysql>
quickFALSE
rawFALSE
reconnectTRUE
shared-memory-base-name(Nodefaultvalue)
socket(Nodefaultvalue)
sslFALSE
ssl-ca(Nodefaultvalue)
ssl-capath(Nodefaultvalue)
ssl-cert(Nodefaultvalue)
ssl-cipher(Nodefaultvalue)
ssl-key(Nodefaultvalue)
ssl-verify-server-certFALSE
tableFALSE
debug-infoFALSE
user(Nodefaultvalue)
safe-updatesFALSE
i-am-a-dummyFALSE
connect_timeout0
max_allowed_packet16777216
net_buffer_length16384
select_limit1000
max_join_size1000000
secure-authFALSE
show-warningsFALSE</pre>