MySQL的管理,包括新建賬戶、基本信息查看



    上篇博文介紹瞭如何安裝MySQL,本文會對如何操作MySQL數據庫進行介紹。首先登陸進入mysql>狀態。

1  mysql>狀態下,輸入命令:

    help  help contents

    可以得到很多幫助信息:

    Help

    Note that all text commands must be firston 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.

    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.

    notee    (\t) Don't write into outfile.

    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.

    tee      (\T) Set outfile [to_outfile]. Append everything into given outfile.

    use      (\u) Use another database. Takesdatabase name as argument.

    charset  (\C) Switch to another charset. Might be needed for processing binlogwith multi-byte charsets.

    warnings (\W) Show warnings after every statement.

    Nowarning (\w) Don't show warnings after every statement.

    Resetconnection (\x) Clean session context.

    【注意,每行命令必須以分號結束。】

    Help contents

    For more information, type 'help<item>', where <item> is one of the following

    categories:

      Account Management

      Administration

      Compound Statements

      Data Definition

      Data Manipulation

      Data Types

      Functions

      Functions and Modifiers for Use with GROUP BY

      Geographic Features

      Help Metadata

      Language Structure

      Plugins

      Procedures

      Storage Engines

      Table Maintenance

      Transactions

      User-Defined Functions

      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 USER

      CREATE USER

      DROP USER

      GRANT

      RENAME USER

      REVOKE

      SET PASSWORD

 

2  建立mysql賬戶

    Mysql 有一個默認數據庫:

    輸入命令:

    use mysql;

    select * from user ;

可以看到裏面存儲的用戶信息,包括很多字段。

 

示例輸出:

命令:select host,user,select_priv,insert_priv from user ;




3 創建用戶:

mysql> insert into user(host,user,authentication_string,select_priv,insert_priv,update_priv,ssl_cipher,x509_issuer,x509_subject)values('localhost','luise2','luise222','y','y','y','y','y','y');


Query OK, 1 row affected (0.05 sec)

查詢如下:


使用PASSWORD()函數對密碼加密

insert into user(host,user,authentication_string,select_priv,insert_priv,update_priv,ssl_cipher,x509_issuer,x509_subject)values('localhost','luise3',PASSWORD('luise333'),'y','y','y','y','y','y');



【注意,我們使用FLUSH PRIVILEGES 語句,讓服務器重新加載授權表。就可以立馬使用新賬戶連接賬戶】


下面列出了一些重要且經常會用到的MySQL命令:

USE Databasename 用於在MySQL工作區內選擇具體某個數據庫。

SHOW DATABASES 列出 MySQL DBMS 所能訪問的數據庫。


SHOW TABLES 一旦數據庫被 use 命令選中,顯示數據庫中的表。


SHOW COLUMNS FROM tablename 顯示錶的屬性、屬性類型、鍵信息、是否允許 NULL 值,默認值,以及其他一些信息。

SHOW INDEX FROM tablename 顯示錶中所有索引的細節信息,包括PRIMARY KEY

SHOW TABLE STATUS LIKE tablename\G 報告MySQL DBMS的性能及統計的細節信息。 【注意表名必須加單引號,不然會出錯】



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章