编者按:
学习的基础从使用工具开始。
【免责声明】本公众号文章仅代表个人观点,与任何公司无关,仅供参考。

编辑|SQL和数据库技术(ID:SQLplusDB)
MySQL数据库客户端工具是mysql命令行,通过mysql可以连接数据库,执行SQL命令和数据库进行交互。
连接选项
启动mysql命令行的时候有很多选项,最常用的是连接选项:
-u, --user=user:指定用户名。-p, --password[=password]:指定密码。-h, --host=host:指定服务器IP或域名,默认为localhost。-P, --port=port:指定服务器端口,默认为3306。--protocol=protocol:指定连接协议,可为tcp、socket、pipe、memory。如使用localhost作为主机名,默认使用socket。
例:
ubuntu@mysql-vm:~$ mysql -u root -prootroot -h localhostmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 14Server version: 8.0.30-0ubuntu0.20.04.2 (Ubuntu)Copyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
其他选项可以参考在线文档。
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html
命令行帮助内容
可以通过help 或者 \h命令查看帮助内容。
mysql> helpFor information about MySQL products and services, visit:http://www.mysql.com/For developer information, including the MySQL Reference Manual, visit:http://dev.mysql.com/To buy MySQL Enterprise support, training, or other products, visit:https://shop.mysql.com/List of all MySQL commands:Note that all text commands must be first on line and end with ';'? (\?) Synonym for `help'.clear (\c) Clear the current input statement.connect (\r) Reconnect to the server. Optional arguments are db and host.delimiter (\d) Set statement delimiter.edit (\e) Edit command with $EDITOR.ego (\G) Send command to mysql server, display result vertically.exit (\q) Exit mysql. Same as quit.go (\g) Send command to mysql server.help (\h) Display this help.nopager (\n) Disable pager, print to stdout.notee (\t) Don't write into outfile.pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.print (\p) Print current command.prompt (\R) Change your mysql prompt.quit (\q) Quit mysql.rehash (\#) Rebuild completion hash.source (\.) Execute an SQL script file. Takes a file name as an argument.status (\s) Get status information from the server.system (\!) Execute a system shell command.tee (\T) Set outfile [to_outfile]. Append everything into given outfile.use (\u) Use another database. Takes database name as argument.charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.warnings (\W) Show warnings after every statement.nowarning (\w) Don't show warnings after every statement.resetconnection(\x) Clean session context.query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.ssl_session_data_print Serializes the current SSL session data to stdout or fileFor server side help, type 'help contents'
参考:
https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
SQL命令的帮助内容
可以通过help contents命令来查看SQL命令的帮助内容。
mysql> help contentsYou asked for help about help category: "Contents"For more information, type 'help <item>', where <item> is one of the followingcategories:Account ManagementAdministrationComponentsCompound StatementsContentsData DefinitionData ManipulationData TypesFunctionsGeographic FeaturesHelp MetadataLanguage StructureLoadable FunctionsPluginsPrepared StatementsReplication StatementsStorage EnginesTable MaintenanceTransactionsUtilitymysql> help Account ManagementYou asked for help about help category: "Account Management"For more information, type 'help <item>', where <item> is one of the followingtopics:ALTER RESOURCE GROUPALTER USERCREATE RESOURCE GROUPCREATE ROLECREATE USERDROP RESOURCE GROUPDROP ROLEDROP USERGRANTRENAME USERREVOKESET DEFAULT ROLESET PASSWORDSET RESOURCE GROUPSET ROLEmysql> help AdministrationYou asked for help about help category: "Administration"For more information, type 'help <item>', where <item> is one of the followingtopics:BINLOGCACHE INDEXFLUSHHELP COMMANDKILLLOAD INDEXRESETRESET PERSISTRESTARTSETSET CHARACTER SETSET CHARSETSET NAMESSHOWSHOW BINARY LOGSSHOW BINLOG EVENTSSHOW CHARACTER SETSHOW COLLATIONSHOW COLUMNSSHOW CREATE DATABASESHOW CREATE EVENTSHOW CREATE FUNCTIONSHOW CREATE PROCEDURESHOW CREATE SCHEMASHOW CREATE TABLESHOW CREATE TRIGGERSHOW CREATE USERSHOW CREATE VIEWSHOW DATABASESSHOW ENGINESHOW ENGINESSHOW ERRORSSHOW EVENTSSHOW FIELDSSHOW FUNCTION CODESHOW FUNCTION STATUSSHOW GRANTSSHOW INDEXSHOW MASTER LOGSSHOW MASTER STATUSSHOW OPEN TABLESSHOW PLUGINSSHOW PRIVILEGESSHOW PROCEDURE CODESHOW PROCEDURE STATUSSHOW PROCESSLISTSHOW PROFILESHOW PROFILESSHOW RELAYLOG EVENTSSHOW REPLICA STATUSSHOW REPLICASSHOW SCHEMASSHOW SLAVE HOSTSSHOW SLAVE STATUSSHOW STATUSSHOW TABLE STATUSSHOW TABLESSHOW TRIGGERSSHOW VARIABLESSHOW WARNINGSSHUTDOWNmysql> help ComponentsYou asked for help about help category: "Components"For more information, type 'help <item>', where <item> is one of the followingtopics:CLONEINSTALL COMPONENTUNINSTALL COMPONENTUNINSTALL PLUGINmysql> help Compound StatementsYou asked for help about help category: "Compound Statements"For more information, type 'help <item>', where <item> is one of the followingtopics:BEGIN ENDCASE STATEMENTCLOSEDECLARE CONDITIONDECLARE CURSORDECLARE HANDLERDECLARE VARIABLEFETCHGET DIAGNOSTICSIF STATEMENTITERATELABELSLEAVELOOPOPENREPEAT LOOPRESIGNALRETURNSIGNALWHILEmysql> help ContentsYou asked for help about help category: "Contents"For more information, type 'help <item>', where <item> is one of the followingcategories:Account ManagementAdministrationComponentsCompound StatementsContentsData DefinitionData ManipulationData TypesFunctionsGeographic FeaturesHelp MetadataLanguage StructureLoadable FunctionsPluginsPrepared StatementsReplication StatementsStorage EnginesTable MaintenanceTransactionsUtilitymysql> help Data DefinitionYou asked for help about help category: "Data Definition"For more information, type 'help <item>', where <item> is one of the followingtopics:ALTER DATABASEALTER EVENTALTER FUNCTIONALTER INSTANCEALTER LOGFILE GROUPALTER PROCEDUREALTER SCHEMAALTER SERVERALTER TABLEALTER TABLESPACEALTER VIEWCREATE DATABASECREATE EVENTCREATE FUNCTIONCREATE INDEXCREATE LOGFILE GROUPCREATE PROCEDURECREATE SCHEMACREATE SERVERCREATE SPATIAL REFERENCE SYSTEMCREATE TABLECREATE TABLESPACECREATE TRIGGERCREATE VIEWDROP DATABASEDROP EVENTDROP FUNCTIONDROP INDEXDROP PROCEDUREDROP SCHEMADROP SERVERDROP SPATIAL REFERENCE SYSTEMDROP TABLEDROP TABLESPACEDROP TRIGGERDROP VIEWFOREIGN KEYRENAME TABLETRUNCATE TABLEmysql> help Data ManipulationYou asked for help about help category: "Data Manipulation"For more information, type 'help <item>', where <item> is one of the followingtopics:CALLDELETEDODUALHANDLERIMPORT TABLEINSERTINSERT DELAYEDINSERT SELECTJOINLOAD DATALOAD XMLPARENTHESIZED QUERY EXPRESSIONSREPLACESELECTTABLEUNIONUPDATEVALUES STATEMENTmysql> help Data TypesYou asked for help about help category: "Data Types"For more information, type 'help <item>', where <item> is one of the followingtopics:AUTO_INCREMENTBIGINTBINARYBITBLOBBLOB DATA TYPEBOOLEANCHARCHAR BYTEDATEDATETIMEDECDECIMALDOUBLEDOUBLE PRECISIONENUMFLOATINTINTEGERLONGBLOBLONGTEXTMEDIUMBLOBMEDIUMINTMEDIUMTEXTSET DATA TYPESMALLINTTEXTTIMETIMESTAMPTINYBLOBTINYINTTINYTEXTVARBINARYVARCHARYEAR DATA TYPEmysql> help FunctionsYou asked for help about help category: "Functions"For more information, type 'help <item>', where <item> is one of the followingcategories:Aggregate Functions and ModifiersBit FunctionsCast Functions and OperatorsComparison OperatorsDate and Time FunctionsEncryption FunctionsEnterprise Encryption FunctionsFlow Control FunctionsGROUP BY Functions and ModifiersGTIDInformation FunctionsInternal FunctionsLocking FunctionsLogical OperatorsMiscellaneous FunctionsNumeric FunctionsPerformance Schema FunctionsSpatial FunctionsString FunctionsWindow FunctionsXMLmysql> help Geographic FeaturesYou asked for help about help category: "Geographic Features"For more information, type 'help <item>', where <item> is one of the followingtopics:GEOMETRY HIERARCHYSPATIAL COLUMNSSPATIAL INDEXEScategories:MBRWKTmysql> help Help MetadataYou asked for help about help category: "Help Metadata"For more information, type 'help <item>', where <item> is one of the followingtopics:HELP_DATEHELP_VERSIONmysql> help Language StructureYou asked for help about help category: "Language Structure"For more information, type 'help <item>', where <item> is one of the followingtopics:FALSETRUEmysql> help Loadable FunctionsYou asked for help about help category: "Loadable Functions"For more information, type 'help <item>', where <item> is one of the followingtopics:CREATE FUNCTION LOADABLE FUNCTIONDROP FUNCTION LOADABLE FUNCTIONmysql> help PluginsName: 'SHOW PLUGINS'Description:Syntax:SHOW PLUGINSSHOW PLUGINS displays information about server plugins.Example of SHOW PLUGINS output:mysql> SHOW PLUGINS\G*************************** 1. row ***************************Name: binlogStatus: ACTIVEType: STORAGE ENGINELibrary: NULLLicense: GPL*************************** 2. row ***************************Name: CSVStatus: ACTIVEType: STORAGE ENGINELibrary: NULLLicense: GPL*************************** 3. row ***************************Name: MEMORYStatus: ACTIVEType: STORAGE ENGINELibrary: NULLLicense: GPL*************************** 4. row ***************************Name: MyISAMStatus: ACTIVEType: STORAGE ENGINELibrary: NULLLicense: GPL...URL: https://dev.mysql.com/doc/refman/8.0/en/show-plugins.htmlmysql> help Prepared StatementsYou asked for help about help category: "Prepared Statements"For more information, type 'help <item>', where <item> is one of the followingtopics:DEALLOCATE PREPAREDROP PREPAREEXECUTE STATEMENTPREPAREmysql> help Replication StatementsYou asked for help about help category: "Replication Statements"For more information, type 'help <item>', where <item> is one of the followingtopics:CHANGE MASTER TOCHANGE REPLICATION FILTERCHANGE REPLICATION SOURCE TOPURGE BINARY LOGSPURGE MASTER LOGSRESET MASTERRESET REPLICARESET SLAVESET SQL_LOG_BINSTART REPLICASTART SLAVESTOP REPLICASTOP SLAVEmysql> help Storage EnginesName: 'Storage Engines'Description:MERGEExamples:Nmysql> help Table MaintenanceYou asked for help about help category: "Table Maintenance"For more information, type 'help <item>', where <item> is one of the followingtopics:ANALYZE TABLECHECK TABLECHECKSUM TABLEOPTIMIZE TABLEREPAIR TABLEmysql> help TransactionsYou asked for help about help category: "Transactions"For more information, type 'help <item>', where <item> is one of the followingtopics:BEGINCOMMITLOCK INSTANCE FOR BACKUPLOCK TABLESRELEASE SAVEPOINTROLLBACKROLLBACK TO SAVEPOINTSAVEPOINTSET TRANSACTIONSTART TRANSACTIONXAmysql> help UtilityYou asked for help about help category: "Utility"For more information, type 'help <item>', where <item> is one of the followingtopics:DESCDESCRIBEEXPLAINHELP STATEMENTUSEmysql>
参考:
https://dev.mysql.com/doc/refman/8.0/en/mysql.htmlhttps://dev.mysql.com/doc/refman/8.0/en/programs-client.html
后续文章更加精彩,欢迎关注本公众号。
——End——
专注于技术不限于技术!
用碎片化的时间,一点一滴地提高数据库技术和个人能力。
欢迎关注!
MySQL相关:
手把手教你在Windows 10安装MySQL 8.0(详细图文)
MySQL入门:Linux 6 RPM方式安装MySQL 8.0
MySQL入门02:关于MySQL连接的ABC
MySQL入门03:MySQL修改root密码的方法
Oracle 和 Mysql 的索引在Null字段上处理的异同
MySQL 5.6认证考试将于2020年9月30日停考
又是一个时代进程,MySQL 5.6结束其生命周期(EOL)
适合MySQL小白的书:我的译作《MySQL基础教程》
文章转载自SQL和数据库技术,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




