学习二:MySql数据库的基本操作
标签(空格分隔): mysql
一,基于命令行的基本操作
- 查看mysql服务是否启动
net start "mysql"
- 停止mysql服务
net stop mysql
配置mysql的环境变量
将mysql的bin目录路径添加到系统环境变量PATH中
登陆mysql数据库
mysql -h localhost -u root -p
- 创建数据库
create database my_school; //创建数据库
show databases; //显示数据库
drop database my_school; //删除数据库
- 创建数据表
create database school;
use school;
create table student(
name varchar(20) not null comment '姓名',
sid int(10) not null primary key,
major varchar(50) not null default '电器工程与自动化',
tel varchar(11) not null unique key,
birthday date not null
);
show tables from school; //查看数据库下面的所有表
show columns from student from school; //查看某个表的具体列的信息
describe school.student; //查看某个表的信息
describe school.student name; //查看某个表的某个字段的信息
- 修改表的结构
use school;
alter table student rename new_student; //重命名表的名称
alter table school.new_student change name new_name varchar(20) not null;//修改表的某个字段的名称
alter table school.new_student change new_name new_name varchar(40);//修改表的某个字段的数据类型
alter table school.new_student change major major varchar(50) not null default '计算机科学';//修改表的某个字段的默认值
alter table school.new_student add email varchar(50) not null comment '邮箱';//添加一个新的字段
alter table school.new_student drop email;//删除一个字段
- 删除表
drop table if exists school.new_student;
- 备份数据库(mysql5.7)
还原数据库(mysql5.7)
首先执行数据库创建脚本