mysql 常用的命令集合

2022-02-17 03:37:52 字數 1460 閱讀 9721

1.建立表

create table `cardpcitrue`(

`id` int auto_increment not null primary key comment'編號',

`cid` int null comment'點卡編號',

`path` varchar(200) null comment'路徑',

`ratetime` timestamp default now() not null comment'建立時間時間'

)engine=innodb default charset=utf8 comment='點卡子集表';

其中innodb時儲存引擎,提供事務支援事務,外部鍵等高階資料庫功能。行級鎖。

區別於myisam表級鎖,適合大量的查詢,不支援事務,資料以檔案形式存在移植性好。

2.增加表的字段。

語法:     alter  table 表名 add 欄位名  資料型別 [屬性];

例: alter table `student`  add  `password `  varchar(32)  not  null;向學生表中新增密碼的字段。

語法: alter  table 表名 change  原欄位名  新欄位名 資料型別[屬性];

例: alter table `student`  change  `password`  `pwd`char(12)  notnull;修改學生表中的密碼欄位的名稱和屬性。

語法: alter table 表名  drop 欄位名;

例: alter  table `student` drop  `pwd`;  刪除學生表中的密碼字段

語法: alter  table  表名  add  constraint 主鍵名 peimary  key 表名(主鍵字段);

例: alter  table `student`  add constraint 『pk_student』  primary  key `student`(`studentno`);把學生表中的學號設定為主鍵列

語法: alter  table  主表名  add constraint 外鍵名 foreign key (外來鍵字段)references  關聯從表名(關聯字段);

例:  alter  table  `student`  add  constraint  `fk_student_grade` foreign  key(`gradeid`)  references  `grade`(`gradeid`);把學生表和年級表中的年級字段設定為主外來鍵關係。

7.建立使用者並賦值許可權。

/*建立本地使用者card,密碼0000*/

grant all on gamecard.* to `card`@`localhost` identified by '0000'

給資料庫gamecard建立了使用者card密碼0000

mysql命令集合

測試環境 mysql 5.0.45 注 可以在mysql中通過mysql select version 來檢視資料庫版本 整理 leo 一 連線mysql。格式 mysql h主機位址 u使用者名稱 p使用者密碼 1 連線到本機上的mysql。首先開啟dos視窗,然後進入目錄mysql bin,再鍵...

mysql命令集合

一 連線mysql。1 連線到本機上的mysql。首先開啟dos視窗,然後進入目錄mysql bin,再鍵入命令mysql u root p,回車後提示你輸密碼.注意使用者名稱前可以有空格也可以沒有空格,但是密碼前必須沒有空格,否則讓你重新輸入密碼.如果剛安裝好mysql,超級使用者root是沒有密...

mysql命令集合

問題一 登入 mysql u root p enter password 報錯 error 2002 hy000 can t connect to local mysql server through socket var lib mysql mysql.sock 2 檢視配置檔案 cat etc ...