標籤:int des into set 操作 key 速度 操作檔案夾 增刪改
#1 操作檔案夾(庫)
增
create database db1 charset utf8;
查
show databases;
show create database db1;
改
alter database db1 charset gbk;
刪
drop database db1;
#2 操作檔案(表)
切換到檔案夾下:use db1
增
create table t1(id int,name char(10))engine=innodb;
create table t2(id int,name char(10))engine=innodb default charset utf8;
查
show tables;
show create table t1;
desc t1;#查看錶結構
改
alter table t1 add age int;
alter table t1 modify name char(12);
刪
drop table t1;
#3 操作檔案的一行行內容(記錄)
增
insert into db1.t1 values(1,‘egon1‘),(2,‘egon2‘),(3,‘egon3‘);
insert into db1.t1(name) values(‘egon1‘),(‘egon2‘),(‘egon3‘);
查
select * from t1;
select name from t1;
select name,id from t1;
改
update t1 set name=‘SB‘ where id=4;
update t1 set name=‘SB‘ where name=‘alex‘;
刪
delete from t1 where id=4;
#對於清空表記錄有兩種方式,但是推薦後者
delete from t1;
truncate t1; #當資料量比較大的情況下,使用這種方式,刪除速度快
#自增id
create table t5(id int primary key auto_increment,name char(10));
create table t4(id int not null unique,name char(10));
insert into t5(name) values
#建立使用者
create user ‘lin‘@‘localhost‘ identified by ‘123‘;
#insert,delele,update,select
#層級1:對所有庫,下的所有表,下的所有欄位
grant select on *.* to ‘lin1‘@‘localhost‘ identified by ‘123‘;
#層級2:對db1庫,下的所有表,下的所有欄位
grant select on db1.* to ‘lin2‘@‘localhost‘ identified by ‘123‘;
#層級3:對錶db1.t1,下的所有欄位
grant select on db1.t1 to ‘lin3‘@‘localhost‘ identified by ‘123‘;
#層級4:對錶db1.t1,下的id,name欄位
grant select (id,name) on db1.t1 to ‘lin4‘@‘localhost‘ identified by ‘123‘;
grant select (id,name),update (name) on db1.t1 to ‘lin5‘@‘localhost‘ identified by ‘123‘;
#修改完許可權後,要記得重新整理許可權
flush privileges;
mysql--增刪改查