mysql 增刪改查

2022-07-23 06:42:10 字數 1870 閱讀 8937

#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增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...

mysql建刪改查 MySQL增刪改查

登入mysql mysql u root p 密碼 建立使用者 mysql insert into mysql.user host,user,password values localhost test password 1234 這樣就建立了乙個名為 test 密碼為 1234 的使用者。注意 此...