創(chuàng)建表
mysql> create table user(
-> id int not null auto_increment primary key,
-> name char(255) not null,
-> password char(255) not null
-> );
查看數(shù)據(jù)庫字符集
show create database demo1;
輸出:
| demo1 | CREATE DATABASE
demo1/*!40100 DEFAULT CHARACTER SET utf8 */ |
改變默認字符集
alter database demo1 default character set 'gbk';
查看所有表
使用 show tables;
2.png
查看表結(jié)構(gòu)
desc <表名>;
1.png
向表中插入數(shù)據(jù)
insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);
3.png
查詢表中的數(shù)據(jù)
select * from user;
4.png
按特定條件查詢:
where 關(guān)鍵字
5.png
更新表中的數(shù)據(jù)
update 表名稱 set 列名稱=新值 where 更新條件;
6.png
刪除表中的數(shù)據(jù)
delete from 表名稱 where 刪除條件;
創(chuàng)建后表的修改
基本形式: alter table 表名 add 列名 列數(shù)據(jù)類型 [after 插入位置]
添加列
alter table student add column remark varchar(20)
修改列
基本形式:alter table 表名 change 列名稱 列新名稱 新數(shù)據(jù)類型;
刪除列
基本形式:alter table 表名 drop 列名稱;
刪除整張表
基本形式:drop table 表名;
刪除整個數(shù)據(jù)庫
基本形式: drop database 數(shù)據(jù)庫名;
修改列類型
alter table student modify remark varchar(100);
修改列名字
alter table student change remark<舊名字> mark<新名字> varchar(20)
修改表名字
alter table student rename to teacher
給個github follow me的鏈接,上面有很多初學者可供學習的資料狸页,項目.
<a>https://github.com/SuperZee</a>