show databases;# 查看有哪些数据库
create database test;#创建名为test的数据库
use test;#使用名为test的数据库# 创建名为student 的数据库
create table student(
id bigint primary key auto_increment,
name varchar(20),
age int,
chi int,
math int,
english int
) charset=utf8 engine=InnoDB #指定字符集和编码# 手动插入数据
insert into student(name, age, chi, math, english) values('用户1', 18, 98, 88, 90)# 创建插入测试数据的自定义函数
create function ins_data(num int) returns int(11)begin
declare i default 0;while i < num do
insert into student(name, age, chi, math, english) values(concat('用户', i), floor(rand()*100), floor(rand()*100), floor(rand()*100), floor(rand()*100));set i = i + 1;endwhile;return i;endselect ins_data(20);# 创建20条测试数据
2. 其它一些常见命令
# 修改字符集
alter table student charset utf8
# 输出表数据
delete from student
# 删除表
drop table student
# 删除ins_data函数
drop function ins_data