一、数据库基本操作
mysql -uroot -p
mysql -uroot -pXXX
exit/quit/ctrl+d
select now();
select version();
show databases;
create database python charset=utf8;
show create database python;
select database();
drop database python;
use python;
show tables;
create table xxx(id int, name varchar(30));
create table yyy(
id int primary key not null auto_increment,
name varchar(30)
);
desc xxx;
create table students(
id int unsigned not null auto_increment primary key,
name varchar(30),
age tinyint unsigned default 0,
high decimal(5, 2),
gender enum("男", "女", "中性", "保密") default "保密",
cls_id int unsigned
);
insert into students values(0, "suger", 18, 188.88, '男', 0);
select * from students;
create table classes(
id int unsigned not null auto_increment primary key,
name varchar(30)
);
alter table students add birthday datetime;
alter table students modify birthday date;
alter table students change birthday birth date default "2000-01-01"
alter table students drop high;
drop table xxx;
show create table students;
二、数据表的操作
show tables;
create table xxx(id int, name varchar(30));
create table yyy(
id int primary key not null auto_increment,
name varchar(30)
);
desc xxx;
create table students(
id int unsigned not null auto_increment primary key,
name varchar(30),
age tinyint unsigned default 0,
high decimal(5, 2),
gender enum("男", "女", "中性", "保密") default "保密",
cls_id int unsigned
);
insert into students values(0, "suger", 18, 188.88, '男', 0);
select * from students;
create table classes(
id int unsigned not null auto_increment primary key,
name varchar(30)
);
alter table students add birthday datetime;
alter table students modify birthday date;
alter table students change birthday birth date default "2000-01-01"
alter table students drop high;
drop table xxx;
show create table students;
三、增删改
1.增加
insert into classes values(0, "abc");
insert into students values(0, "aaa", 20, '女', 1, '1900-01-01');
insert into students values(null, "aaa", 20, '女', 1, '1900-01-01');
insert into students values(default, "aaa", 20,<