進入虛拟機,首先su,然後輸入password,進入root模式。在root模式下輸入MySQL。
建立名為my的表,書寫語句為:create database my charset utf8; (注:這裡的database,勿寫成batabases)
use my;
show tables;
新增表:create table my (ID int(3),name varchar(10),sex varchar(10),birth varchar(10),department varchar(20),address varchar(30))charset utf8;
檢視表結構:desc my;
表字段的增、删、改、查
增:alter table 表名 add 字段名 資料類型 【位置】;
删:alter table 表名 drop 字段名;
改:alter table 表名 modify 字段 資料類型 【位置】
重命名:alter table 表名 change oldname newname 資料類型 【位置】
資料的增、删、改、查
增:insert into 表名(例1,例2,.......)values (v1,v2,.......);
删:delete from 表名 where 條件;
改:update 表名 set 字段=‘值’【where 條件】;
查:select */字段清單 from 表名 【where 條件】;
增資料:insert into my(ID,name,sex,birth,department,address) values (901,'zahnglaoda','nan','1985','jisuanjixi','beijingshihaidianqu');
改資料:update my set address = 'shanxishengxianshi' where ID=904;
查資料: select * from my;
總結:資料庫
庫操作:
(1)新增資料庫:create database 名 charset utf8;
(2)檢視所有資料庫:show databases;
(3)檢視某一資料庫:use 名;show tables;
(4)檢視某一類似“A”資料庫:show databases like 'A';
(5)删除:drop databases 名;
表操作:
(1)新增表:create table 名 (字段名,類型,......)charset utf8;
(2)檢視所有表:show tables;
(3)檢視部分表:show tables like ' ';
(4)檢視表結構: desc 表名;
(5)修改表名:rename table oldname to newname;
(6)删除表:drop table 表1,表2,......;
字段操作:
A表字段:
增:alter table 表名 add 字段名 資料類型 【位置】;
删:alter table 表名 drop 字段名;
改:alter table 表名 modify 字段 資料類型 【位置】;
重命名:alter table 表名 change oldname newname 資料類型 【位置】;
B資料
增:insert into 表名(例1,例2,.......)values (v1,v2,.......);
删:delete from 表名 where 條件;
改:update 表名 set 字段=‘值’【where 條件】;
查:select */字段清單 from 表名 【where 條件】;