MySQL 相關命令

2021-08-30 12:05:26 字數 1102 閱讀 2785

1 mysql 資料庫表 增加一列

alter table 表名  add 列名 資料型別  not null  after 列名 ;

eg:alter table `menutree` add `target` varchar(50) null after `action` ;

2 修改資料庫表列

alter table `表名` change `列名1` `列名1` varchar(60) not null  ;

eg:alter table `menutree` change `target` `target` varchar(50) not null  ;

3 刪除資料庫列:

alter table `表名` drop `列名` ;

eg:alter table `menutree` drop `test` ;

4:修改資料庫表列的資料型別:

alter table `menutree` change `parentid` `parentid` int(3) not null  ;

5 新增索引:

alter table `表名` add index `索引名` (`列1`, `列2`) ;

eg:alter table `menutree` add index `newindex` (`id`, `text`) ;

6 刪除索引:

alter table `表名` drop index `索引名` ;

eg:alter table `menutree` drop index `newindex` ;

7 修改主鍵資訊:

alter table `menutree` change `id` `id` int(50) default null null auto_increment , add primary key(`id`) ;

8 修改資料庫表列是否為null

alter table `表名` change `列名` `列名` varchar(200) default '' null  ;

eg:alter table `menutree` change `action` `action` varchar(200) default '' null  ;

Mysql相關命令

2 執行sql指令碼檔案 方法一使用cmd命令執行 windows下,unix或linux在的其控制台下 d mysql bin mysql uroot p123456 dtest注意 a 如果在sql指令碼檔案中使用了use 資料庫,則 d資料庫選項可以忽略 b 如果 mysql的bin目錄 中包...

MySQL 相關命令

1.啟動和關閉資料庫 net start mysql net stop mysql 2.通過 cmd 命令視窗進入 mysql 注意 首先要確定在電腦上已經安裝好 mysql,並且 mysql 服務已經開啟。進入cmd,輸入使用者名稱,密碼,進入到mysql,命令如下 mysql u使用者名稱 p密...

mysql相關命令

d database name 開啟指定資料庫 delimiter name 指定分隔符 h host name 伺服器的名稱 p 密碼 p port 是埠號 prompt name 設定提示符 v version 輸出版本資訊並且退出 mysql 退出 1.exit 2.quit 3.q 顯示當前...