1.打开数据库,用户名为root,密码为123456
mysql -uroot -p123456
2.创建库,该语句的意思为如果test库不存在则创建,CHARSET utf8 COLLATE utf8_general_ci为不区分大小写插入数据
CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
3.直接创建库
create database test;
4.显示存在的库
show databases;
5.删除库
drop database test;
6.使用test库
use test;
7.显示存在的表
show tables;
8.显示当前使用的是哪个库
select database();
9.查看指定表的建表语句
show creat table students;
10.查看表是否有默认提交
show variables like ‘autocommit’;
11.给表加索引
ALTER TABLE ‘student’ ADD INDEX stu_id_index (‘name’);
12.新建表
create table students(id int not null,
student_id varchar(20) not null,
name varchar(30) not null,
sex char(4))
13.插入数据
insert into students values(1001,2001,‘小明’,‘男’)