--连接认证
mysql.exe -h localhost -P 3306 -u root -p
mysql -u root -p
-- 查看所有数据库
show databases;
--退出命令
exit、quit、\q
--创建数据库
create database mydatabase charset utf8;
--创建关键字数据库
create database database charset utf8;
--告诉服务器当前中文的字符集是什么
set names gbk;
--创建中文数据库
create database database 中国 charset utf8;
--查看数据库
create database informationtest charset utf8;
--查看以information_开始的数据库
show databes like 'informatinon\_%';
show databes like 'information_%'; --相当于information%
--查看数据库的创建语句
show create database mydatabase;
show create database database';
--修改数据库informationtest的字符集
alter darabase informationtast charset GBK;
--删除数据库
drop database (informationtast)数据库名字;
--创建表
create table if not exists mydatabase.stydent(
--显示地将student表放到mydatabase数据库下
name varchar(10),
gender varchar(10),
number varchar(10),
age int
)charset utf8;
--创建数据库表
--进入数据库
use mydatabase;
--创建表
create table class(
name varchar(10),
room varchar(10)
)charset utf8;
--查看所有表
show tables;
--查看以s结尾的表
show tables like '%s';
--查看表的创建语句
show create table student;
show create table student;\g
show create table student;\G --将查到的结构旋转90度变成纵向
--查看表结构
desc cless;
describe class;
show columns from class;
--重命名表(student表 -> my_student)
rename table student to my_student;
-- 修改表选项:字符集
alter table my_student charset = GBK;
--给学生表增加ID,放到第一个位置
alter table mt_student add column id int first;
--将学生表中的number学号字段变成固定传唱度,且放倒第二位(id之后)
alter table my_student modify number char(10) after id;
--修改学生表中的gender字段为sex
alter table my_student drop age;
--删除数据表
drop yable class;
--插入数据
insert into my_student values
(1,'bc20190001','Jim','male'),
(2,'bc20190001','Lily','female');
--插入数据:指定字段列表
insert into my_student(number,sex,name,id) values
('bc20190003','male','Tom',3),
('bc20190003','female','Lucy',4);
--查看所有数据
select * from my_student;
--查看指定字段、指定条件的数九
--查看满足id为1的学生信息
select id, number,sex,name from my_student where='Jim';
--更新数据
update my_student set sex='female' where name='Jim';
--删除数据
delete from my_student where sex='male';