MySQL 服務經常使用操做命令

一、MySQL 服務設置

  • 在使用 mysql.server 命令以前須要將路徑 /usr/local/mysql/support-files 添加到系統環境變量中。html

    export PATH=$PATH:/usr/local/mysql/support-files
  • 在使用 mysql 命令以前須要將路徑 /usr/local/mysql/bin 添加到系統環境變量中。mysql

    export PATH=$PATH:/usr/local/mysql/bin
  • 具體設置請參照《添加系統環境變量》章節。sql

二、MySQL 服務經常使用操做

2.1 MySQL 服務控制命令

  • MySQL 服務控制命令數據庫

    # 啓動 MySQL 服務
    $ sudo mysql.server start
    
        Starting MySQL
        .. SUCCESS!
    # 中止 MySQL 服務
    $ sudo mysql.server stop
    
        Shutting down MySQL
        .. SUCCESS!
    # 重啓 MySQL 服務
    $ sudo mysql.server restart
    
        Shutting down MySQL
        .. SUCCESS! 
        Starting MySQL
        .. SUCCESS!
    # 從新加載
    $ sudo mysql.server reload
    
        SUCCESS! Reloading service MySQL
    # 強制從新加載
    $ sudo mysql.server force-reload
    
        SUCCESS! Reloading service MySQL
    # 查看 MySQL 服務狀態
    $ mysql.server status
    
        ERROR! Multiple MySQL running but PID file could not be found (61998 62083 )

2.2 MySQL 服務鏈接命令

  • MySQL 服務鏈接命令網絡

    # 登陸 MySQL 服務
    # mysql -u 用戶名 -p 密碼
    $ mysql -u root -p
    
        Enter password: 
        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 930
        Server version: 8.0.11 MySQL Community Server - GPL
    
        Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
        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>
    # 登出 MySQL 服務
    > exit
    
        Bye

三、MySQL 服務幫助操做

3.1 按照層次看幫助

  • 若是不知道幫助可以提供什麼,那麼就能夠直接用 「? contents」 命令來顯示全部可供查詢的分類,對於分類可使用 「? 分類名稱」 的方式針對用戶感興趣的內容作進一步的查看,經過這種 「? 類型別名」 的方式,就能夠一層層的往下查找用戶所關心的主題內容。ide

    > ? 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
       Data Definition
       Data Manipulation
       Data Types
       Functions
       Functions and Modifiers for Use with GROUP BY
       Geographic Features
       Help Metadata
       Language Structure
       Plugins
       Storage Engines
       Table Maintenance
       Transactions
       User-Defined Functions
       Utility

3.2 快速查閱幫助

  • 在實際應用中,若是須要快速查閱某項語法時,可使用 「? 關鍵字」 方式進行快速查詢。工具

    > ? insert
    Name: 'INSERT'
    Description:
    Syntax:
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name [, partition_name] ...)]
        [(col_name [, col_name] ...)]
        {VALUES | VALUE} (value_list) [, (value_list)] ...
        [ON DUPLICATE KEY UPDATE assignment_list]
    
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name [, partition_name] ...)]
        SET assignment_list
        [ON DUPLICATE KEY UPDATE assignment_list]
    
    INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        [PARTITION (partition_name [, partition_name] ...)]
        [(col_name [, col_name] ...)]
        SELECT ...
        [ON DUPLICATE KEY UPDATE assignment_list]
    
    value:
        {expr | DEFAULT}
    
    value_list:
        value [, value] ...
    
    assignment:
        col_name = value
    
    assignment_list:
        assignment [, assignment] ...
    
    INSERT inserts new rows into an existing table. The INSERT ... VALUES
    and INSERT ... SET forms of the statement insert rows based on
    explicitly specified values. The INSERT ... SELECT form inserts rows
    selected from another table or tables. INSERT with an ON DUPLICATE KEY
    UPDATE clause enables existing rows to be updated if a row to be
    inserted would cause a duplicate value in a UNIQUE index or PRIMARY
    KEY.
    
    For additional information about INSERT ... SELECT and INSERT ... ON
    DUPLICATE KEY UPDATE, see [HELP INSERT SELECT], and
    http://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html.
    
    In MySQL 8.0, the DELAYED keyword is accepted but ignored by the
    server. For the reasons for this, see [HELP INSERT DELAYED],
    
    Inserting into a table requires the INSERT privilege for the table. If
    the ON DUPLICATE KEY UPDATE clause is used and a duplicate key causes
    an UPDATE to be performed instead, the statement requires the UPDATE
    privilege for the columns to be updated. For columns that are read but
    not modified you need only the SELECT privilege (such as for a column
    referenced only on the right hand side of an col_name=expr assignment
    in an ON DUPLICATE KEY UPDATE clause).
    
    When inserting into a partitioned table, you can control which
    partitions and subpartitions accept new rows. The PARTITION option
    takes a list of the comma-separated names of one or more partitions or
    subpartitions (or both) of the table. If any of the rows to be inserted
    by a given INSERT statement do not match one of the partitions listed,
    the INSERT statement fails with the error Found a row not matching the
    given partition set. For more information and examples, see
    http://dev.mysql.com/doc/refman/8.0/en/partitioning-selection.html.
    
    URL: http://dev.mysql.com/doc/refman/8.0/en/insert.html

3.3 經常使用的網絡資源

  • MySQL 官網 能夠下載到各個版本的 MySQL 以及相關客戶端開發工具等。開發工具

  • MySQL 在線手冊 提供了目前最權威的 MySQL 數據庫及工具的在線手冊。ui

  • MySQL bug 列表 能夠查看到 MySQL 已經發布的 bug 列表,或者向 MySQL 提交 bug 報告。this

  • MySQL 的最新消息 一般會發布各類關於 MySQL 的最新消息。

相關文章
相關標籤/搜索