mysql数据库的操作大全:数据库 表 字段 记录


知识结构:数据库 表 字段 记录
四大操作:增删改查
一、数据库
create database if not exists jkxy;
use jkxy;
show databases;
drop database jkxy;
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;//只导出表结构

 

 

猜你喜欢

转载自www.cnblogs.com/htmlphp/p/12061685.html
今日推荐