暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL客户端工具--mysql命令行

954

编者按:

学习的基础从使用工具开始。


【免责声明】本公众号文章仅代表个人观点,与任何公司无关,仅供参考。


编辑|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 localhost
      mysql: [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 14
      Server 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 its
      affiliates. Other names may be trademarks of their respective
      owners.


      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> help


          For 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 file


          For server side help, type 'help contents'

          参考:

            https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html

            SQL命令的帮助内容

            可以通过help contents命令来查看SQL命令的帮助内容。

              mysql> help contents
              You asked for help about help category: "Contents"
              For more information, type 'help <item>', where <item> is one of the following
              categories:
              Account Management
              Administration
              Components
              Compound Statements
              Contents
              Data Definition
              Data Manipulation
              Data Types
              Functions
              Geographic Features
              Help Metadata
              Language Structure
              Loadable Functions
              Plugins
              Prepared Statements
              Replication Statements
              Storage Engines
              Table Maintenance
              Transactions
              Utility


              mysql> help Account Management
              You asked for help about help category: "Account Management"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              ALTER RESOURCE GROUP
              ALTER USER
              CREATE RESOURCE GROUP
              CREATE ROLE
              CREATE USER
              DROP RESOURCE GROUP
              DROP ROLE
              DROP USER
              GRANT
              RENAME USER
              REVOKE
              SET DEFAULT ROLE
              SET PASSWORD
              SET RESOURCE GROUP
              SET ROLE


              mysql> help Administration
              You asked for help about help category: "Administration"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              BINLOG
              CACHE INDEX
              FLUSH
              HELP COMMAND
              KILL
              LOAD INDEX
              RESET
              RESET PERSIST
              RESTART
              SET
              SET CHARACTER SET
              SET CHARSET
              SET NAMES
              SHOW
              SHOW BINARY LOGS
              SHOW BINLOG EVENTS
              SHOW CHARACTER SET
              SHOW COLLATION
              SHOW COLUMNS
              SHOW CREATE DATABASE
              SHOW CREATE EVENT
              SHOW CREATE FUNCTION
              SHOW CREATE PROCEDURE
              SHOW CREATE SCHEMA
              SHOW CREATE TABLE
              SHOW CREATE TRIGGER
              SHOW CREATE USER
              SHOW CREATE VIEW
              SHOW DATABASES
              SHOW ENGINE
              SHOW ENGINES
              SHOW ERRORS
              SHOW EVENTS
              SHOW FIELDS
              SHOW FUNCTION CODE
              SHOW FUNCTION STATUS
              SHOW GRANTS
              SHOW INDEX
              SHOW MASTER LOGS
              SHOW MASTER STATUS
              SHOW OPEN TABLES
              SHOW PLUGINS
              SHOW PRIVILEGES
              SHOW PROCEDURE CODE
              SHOW PROCEDURE STATUS
              SHOW PROCESSLIST
              SHOW PROFILE
              SHOW PROFILES
              SHOW RELAYLOG EVENTS
              SHOW REPLICA STATUS
              SHOW REPLICAS
              SHOW SCHEMAS
              SHOW SLAVE HOSTS
              SHOW SLAVE STATUS
              SHOW STATUS
              SHOW TABLE STATUS
              SHOW TABLES
              SHOW TRIGGERS
              SHOW VARIABLES
              SHOW WARNINGS
              SHUTDOWN


              mysql> help Components
              You asked for help about help category: "Components"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              CLONE
              INSTALL COMPONENT
              UNINSTALL COMPONENT
              UNINSTALL PLUGIN


              mysql> help Compound Statements
              You asked for help about help category: "Compound Statements"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              BEGIN END
              CASE STATEMENT
              CLOSE
              DECLARE CONDITION
              DECLARE CURSOR
              DECLARE HANDLER
              DECLARE VARIABLE
              FETCH
              GET DIAGNOSTICS
              IF STATEMENT
              ITERATE
              LABELS
              LEAVE
              LOOP
              OPEN
              REPEAT LOOP
              RESIGNAL
              RETURN
              SIGNAL
              WHILE


              mysql> help Contents
              You asked for help about help category: "Contents"
              For more information, type 'help <item>', where <item> is one of the following
              categories:
              Account Management
              Administration
              Components
              Compound Statements
              Contents
              Data Definition
              Data Manipulation
              Data Types
              Functions
              Geographic Features
              Help Metadata
              Language Structure
              Loadable Functions
              Plugins
              Prepared Statements
              Replication Statements
              Storage Engines
              Table Maintenance
              Transactions
              Utility


              mysql> help Data Definition
              You asked for help about help category: "Data Definition"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              ALTER DATABASE
              ALTER EVENT
              ALTER FUNCTION
              ALTER INSTANCE
              ALTER LOGFILE GROUP
              ALTER PROCEDURE
              ALTER SCHEMA
              ALTER SERVER
              ALTER TABLE
              ALTER TABLESPACE
              ALTER VIEW
              CREATE DATABASE
              CREATE EVENT
              CREATE FUNCTION
              CREATE INDEX
              CREATE LOGFILE GROUP
              CREATE PROCEDURE
              CREATE SCHEMA
              CREATE SERVER
              CREATE SPATIAL REFERENCE SYSTEM
              CREATE TABLE
              CREATE TABLESPACE
              CREATE TRIGGER
              CREATE VIEW
              DROP DATABASE
              DROP EVENT
              DROP FUNCTION
              DROP INDEX
              DROP PROCEDURE
              DROP SCHEMA
              DROP SERVER
              DROP SPATIAL REFERENCE SYSTEM
              DROP TABLE
              DROP TABLESPACE
              DROP TRIGGER
              DROP VIEW
              FOREIGN KEY
              RENAME TABLE
              TRUNCATE TABLE


              mysql> help Data Manipulation
              You asked for help about help category: "Data Manipulation"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              CALL
              DELETE
              DO
              DUAL
              HANDLER
              IMPORT TABLE
              INSERT
              INSERT DELAYED
              INSERT SELECT
              JOIN
              LOAD DATA
              LOAD XML
              PARENTHESIZED QUERY EXPRESSIONS
              REPLACE
              SELECT
              TABLE
              UNION
              UPDATE
              VALUES STATEMENT


              mysql> help Data Types
              You asked for help about help category: "Data Types"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              AUTO_INCREMENT
              BIGINT
              BINARY
              BIT
              BLOB
              BLOB DATA TYPE
              BOOLEAN
              CHAR
              CHAR BYTE
              DATE
              DATETIME
              DEC
              DECIMAL
              DOUBLE
              DOUBLE PRECISION
              ENUM
              FLOAT
              INT
              INTEGER
              LONGBLOB
              LONGTEXT
              MEDIUMBLOB
              MEDIUMINT
              MEDIUMTEXT
              SET DATA TYPE
              SMALLINT
              TEXT
              TIME
              TIMESTAMP
              TINYBLOB
              TINYINT
              TINYTEXT
              VARBINARY
              VARCHAR
              YEAR DATA TYPE


              mysql> help Functions
              You asked for help about help category: "Functions"
              For more information, type 'help <item>', where <item> is one of the following
              categories:
              Aggregate Functions and Modifiers
              Bit Functions
              Cast Functions and Operators
              Comparison Operators
              Date and Time Functions
              Encryption Functions
              Enterprise Encryption Functions
              Flow Control Functions
              GROUP BY Functions and Modifiers
              GTID
              Information Functions
              Internal Functions
              Locking Functions
              Logical Operators
              Miscellaneous Functions
              Numeric Functions
              Performance Schema Functions
              Spatial Functions
              String Functions
              Window Functions
              XML


              mysql> help Geographic Features
              You asked for help about help category: "Geographic Features"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              GEOMETRY HIERARCHY
              SPATIAL COLUMNS
              SPATIAL INDEXES
              categories:
              MBR
              WKT


              mysql> help Help Metadata
              You asked for help about help category: "Help Metadata"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              HELP_DATE
              HELP_VERSION


              mysql> help Language Structure
              You asked for help about help category: "Language Structure"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              FALSE
              TRUE


              mysql> help Loadable Functions
              You asked for help about help category: "Loadable Functions"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              CREATE FUNCTION LOADABLE FUNCTION
              DROP FUNCTION LOADABLE FUNCTION


              mysql> help Plugins
              Name: 'SHOW PLUGINS'
              Description:
              Syntax:
              SHOW PLUGINS


              SHOW PLUGINS displays information about server plugins.


              Example of SHOW PLUGINS output:


              mysql> SHOW PLUGINS\G
              *************************** 1. row ***************************
              Name: binlog
              Status: ACTIVE
              Type: STORAGE ENGINE
              Library: NULL
              License: GPL
              *************************** 2. row ***************************
              Name: CSV
              Status: ACTIVE
              Type: STORAGE ENGINE
              Library: NULL
              License: GPL
              *************************** 3. row ***************************
              Name: MEMORY
              Status: ACTIVE
              Type: STORAGE ENGINE
              Library: NULL
              License: GPL
              *************************** 4. row ***************************
              Name: MyISAM
              Status: ACTIVE
              Type: STORAGE ENGINE
              Library: NULL
              License: GPL
              ...


              URL: https://dev.mysql.com/doc/refman/8.0/en/show-plugins.html




              mysql> help Prepared Statements
              You asked for help about help category: "Prepared Statements"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              DEALLOCATE PREPARE
              DROP PREPARE
              EXECUTE STATEMENT
              PREPARE


              mysql> help Replication Statements
              You asked for help about help category: "Replication Statements"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              CHANGE MASTER TO
              CHANGE REPLICATION FILTER
              CHANGE REPLICATION SOURCE TO
              PURGE BINARY LOGS
              PURGE MASTER LOGS
              RESET MASTER
              RESET REPLICA
              RESET SLAVE
              SET SQL_LOG_BIN
              START REPLICA
              START SLAVE
              STOP REPLICA
              STOP SLAVE


              mysql> help Storage Engines
              Name: 'Storage Engines'
              Description:
              MERGEExamples:
              N
              mysql> help Table Maintenance
              You asked for help about help category: "Table Maintenance"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              ANALYZE TABLE
              CHECK TABLE
              CHECKSUM TABLE
              OPTIMIZE TABLE
              REPAIR TABLE


              mysql> help Transactions
              You asked for help about help category: "Transactions"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              BEGIN
              COMMIT
              LOCK INSTANCE FOR BACKUP
              LOCK TABLES
              RELEASE SAVEPOINT
              ROLLBACK
              ROLLBACK TO SAVEPOINT
              SAVEPOINT
              SET TRANSACTION
              START TRANSACTION
              XA


              mysql> help Utility
              You asked for help about help category: "Utility"
              For more information, type 'help <item>', where <item> is one of the following
              topics:
              DESC
              DESCRIBE
              EXPLAIN
              HELP STATEMENT
              USE


              mysql>


              参考:

                https://dev.mysql.com/doc/refman/8.0/en/mysql.html
                https://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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                评论