mysql的基本操作
show databases; select database();show tables; desc table_name; #这几个命令是必须要敲的
创建数据库有两种方法
第一种是用bash命令来创建再授权mysql用户这样也可以
第二种当然是用sql命令来创建了
create database doyouknow ( #创建表
id int(8) unsigned not null primary key increment, #主键的区别就是insert into values的时候值只能是唯一的
name varchar(20) not null default "this is default information and show " comment "this is attructions"
)auto_increment = 100;
#insert 值 :
insert into table_name values (42 , "who are you");
insert into table_name values (null,"sfa"),(null,"fsfasf"),(null, "sdfa"),(null, "sdfap");
# 添加一个字段
alter table table_name add column_name varchar(90) not null default "this is default information" comment "this is attructions";
#添加多个字段
alter table table_name add (
column1 varchar(88) not null default "I like to practice" comment "this is attructions"
column2 varchar(88) not null default "why do you like to practice" comment "Does not affect"
column3 varchar(88) not null default "can not modify" comment "this is attructions"
);
删除一个/或多个字段
alter table table_name drop column colume_name1,drop column column_name2;
#修改字段名字跟类型的同时还可以加上 default "sdfkalj" 跟 comment "sdfafkkk" ,如果字段的值是字符串,那么修改字符段的类型的时候,那个类型一定是要可以装下字符串的类型就可以修改成功,否则反之。
alter table table_name change old_column_name new_column_name char(40) not null default "sdfa" comment "sdfa";
#修改字段的长度的同时还可以加上 default "sdfkalj" 跟 comment "sdfafkkk"
alter table table_name modify column_name varchar(10) not null default "sfa" comment "sfa";
#修改表的名字
alter table old_table_name rename to new_table_name;
update table_name set column_name = replace(column_name,'old_column_values','new_column_values') where column_name like 'old_column_values'; #这个可以只删除一个字段的值