溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux_MySQL(mariadb)數(shù)據(jù)庫上(3)

發(fā)布時(shí)間:2020-07-08 22:44:14 來源:網(wǎng)絡(luò) 閱讀:276 作者:zx337954373 欄目:數(shù)據(jù)庫

 

服務(wù)器端命令:

       DDL:數(shù)據(jù)定義語言,主要用于管理數(shù)據(jù)庫組件,例如表、索引、視圖、用戶、存儲(chǔ)過程

              CREATE、ALTER、DROP

       DML:數(shù)據(jù)操縱語言,主要用管理表中的數(shù)據(jù),實(shí)現(xiàn)數(shù)據(jù)的增、刪、改、查;

              INSERT, DELETE, UPDATE, SELECT

獲取命令幫助:

       mysql> help  KEYWORD

                           

數(shù)據(jù)庫管理:

       創(chuàng)建:CREATE  {DATABASE | SCHEMA}  [IF NOT EXISTS]  db_name;

                     [DEFAULT]  CHARACTER SET [=] charset_name 設(shè)置字符集

                     [DEFAULT]  COLLATE [=] collation_name  排序規(guī)則

例:CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Linux_MySQL(mariadb)數(shù)據(jù)庫上(3)

                                         

              查看支持的所有字符集:SHOW CHARACTER SET

              查看支持的所有排序規(guī)則:SHOW  COLLATION

修改:

       ALTER {DATABASE | SCHEMA}  [db_name]

       [DEFAULT]  CHARACTER SET [=] charset_name

       [DEFAULT]  COLLATE [=] collation_name

                                         

刪除:

       DROP {DATABASE | SCHEMA} [IF EXISTS] db_name

表管理:

       創(chuàng)建:

              CREATE TABLE  [IF NOT EXISTS]  tbl_name  (create_defination表定義)  [table_options]

       create_defination:

              字段:col_name  data_type

                     鍵:

                            PRIMARY KEY (col1, col2, ...) 主鍵約束

                            UNIQUE KEY  (col1, col2,...)       唯一鍵約束

                            FOREIGN KEY (column) 外鍵約束

                     索引:

                            KEY|INDEX  [index_name]  (col1, col2,...)

: CREATE TABLE students(id INT UNSIGNED NOT NULL,name CHAR(30) NOT NULL,age TINYINT UNSIGNED,gender ENUM(f,m) );

創(chuàng)建  表 學(xué)生 (id 整數(shù)型 無符號(hào) 不為空,姓名 字符型(30) 不為空,年齡 小整型 無符號(hào),性別 枚舉(f,m));

UNSIGNED 必須跟在字符型之后 其他次序無所謂

Linux_MySQL(mariadb)數(shù)據(jù)庫上(3)

              查看數(shù)據(jù)庫支持的所有存儲(chǔ)引擎類型:

                                          mysql> SHOW  ENGINES;

查看某表的存儲(chǔ)引擎類型:

                                          mysql> SHOW  TABLES  STATUS  [LIKE  'tbl_name']

              table_options:

                     ENGINE [=] engine_name 存儲(chǔ)引擎類型

修改:

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name  [alter_specification [, alter_specification] ...]                            alter_specification: 字段或?qū)傩?span >

              字段:

                     添加:ADD  [COLUMN]字段名  col_name  data_type  [FIRST | AFTER col_name ]放置位置

            Linux_MySQL(mariadb)數(shù)據(jù)庫上(3)

                     刪除:DROP  [COLUMN] col_name

例:ALTER TABLE student DROP class;

                     修改:

                            CHANGE [COLUMN] old_col_name new_col_name column_definition  [FIRST|AFTER col_name]      

改名字和字段名

                            MODIFY [COLUMN] col_name column_definition  [FIRST | AFTER col_name]

改字段定義(只要不改名字都可用)

例: ALTER TABLE student MODIFY calss VARCHAR(100) AFTER age;

              鍵:

                     添加:ADD  {PRIMARY|UNIQUE|FOREIGN}  KEY (col1, col2,...)

例:ALTER TABLE student ADD UNIQUE KEY (name); 添加唯一鍵 (NULL不為空時(shí)自動(dòng)轉(zhuǎn)換成主鍵)

                     刪除:

                            主鍵:DROP PRIMARY KEY

                            外鍵:DROP FOREIGN KEY fk_symbol

              索引:

                     添加:ADD {INDEX|KEY} [index_name]  (col1, col2,...)

例:ALTER TABLE student ADD INDEX index_calss (class);  index_name為自己起的名字

                     刪除:DROP {INDEX|KEY}  index_name

例:ALTER TABLE  student DROP INDEX name;

              表選項(xiàng):

                     ENGINE [=] engine_name

                                         

       查看表上的索引的信息:

              mysql> SHOW INDEXES FROM tbl_name;

刪除

                                   DROP  TABLE  [IF EXISTS]   tbl_name [, tbl_name] ...

表的引用方式:

                                   tbl_name 相當(dāng)于相對(duì)路徑 必須指定當(dāng)前表(USE db_name;)

                                   db_name.tbl_name 相當(dāng)于絕對(duì)路徑


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI