Encyclopedia mysql database operations: database table column


Knowledge structure: database table fields record
four operations: CRUD
a database
the Create Database IF EXISTS jkxy not;
use jkxy;
Show Databases;
drop Database jkxy;
the rename Database jkxy to jikexueyuan;

二、表
create table if not exists jkxy(
id int(4) not null primary key auto_increment,
name char(20) not null,
sex int(4) not null default '0'
);
show tables;
drop tables jkxy;
rename table jkxy to jikexueyuan;
desc jkxy;

三、字段
alter table jkxy add address char(30) not null after name;
alter table jkxy drop address ;
alter table jkxy change address stu_address;
alter table jkxy add index stu_name(name);
alter table jkxy add primary key(id);
alter table jkxy add unique uni_card(cardnumber);

四、记录
insert into jkxy values('1,'Mike','男');
delete from jkxy where id=1;
update jkxy set name='John', age=19 where id=1 and name='xx';
select * from jkxy;
select id,name from jkxy;
select id,name from jkxy where id>1 or name='xxx';
select id,name as gg from jkxy where id>1;
select count(id) from jkxy;

五、导入导出数据库
导入:
mysql -u root -p 123 jkxy<stu.sql;
source /desktop/stu.sql;
导出:
mysqldump -uroot -p jkxy > jkxy.sql; //导出表结构和数据
mysqldump -uroot -p -d jkxy>jkxy.sql;//只导出表结构

 

 

Guess you like

Origin www.cnblogs.com/htmlphp/p/12061685.html