安装MySql
首先下载MySql,下载地址为https://dev.mysql.com/downloads/windows/installer/5.7.html
MySQL安装成功后,需要配置到环境变量,配置成功后,就可以登录到MySQL了,客户端登录的命令具体为:
mysql -h localhost -u root -p

数据库的管理
database:数据库
table:表 表里面存储数据都是行列的模式
数据类型:
1、varchar(20)
2、int
3、double
创建数据库
create database databaseName;
show databases;

drop database databaseName;


use databaseName;
select database();

select version();

status;

select now();

select now() as 当前时间

show variables like '%connection%';

show variables like '%timeout%';

表的结构管理
查看数据库中有哪些表
show tables;

create table tableName(Field Type(size));

create table uerInfo like user;


desc tableName;

show create table tableName \G;

show create table tableName \g;

create table user(name varchar(20),age int,address varchar(80))ENGINE=InnoDB DEFAULT CHARSET=utf8;


rename table oldTableName to newTableName;

字段管理
添加字段
添加的字段在首位
alter table tableName add addFiled type first; desc tableName;

alter table user add addFiled type after existFiled; desc tableName;

alter table user add addFiled type; desc tableName;

alter table tableName change oldFiled newFiled type; desc tableName;

alter table tableName modify Field newType;

alter table tableName drop Field;
create table user(Field type comment "注释");

alter table tableName modify Field type comment "注释";

字段特性
alter table tableName add Field Type not null;

alter table tableName add Field Type not null default "value";


create table tableName(id int primary key auto_increment ,name varchar(10));


alter table tableName add Field Type UNIQUE;


INSERT
插入一个字段的一个值
insert into std_info(name) values("zhangsan"); select * from std_info;

insert into std_info values("zhangsan",10); select * from std_info;

insert into std_info values("zhangsan",10),("lisi",20),("wangwu",30); select * from std_info;

insert into 目标表 select * from 原有表;

replace into tableName values(1,"wuya",1)

replace解决重复性数据的插入不会出错。
update user set age=25 where id=1;

DELETE
删除一条数据
delete from tableNme where id=x;


delete from tableNme;


truncate table tableName;


SELECT
加载数据
下载数据包,解压后放在桌面
打开一个新的控制台进入test_db-master的目录,然后输入命令:mysql -u root -p <employees.sql,执行导入;

在数据库中查看所有数据库,可查看到导入的数据库employees;

进入到数据库employees,查看此数据库中所有的表。



浙公网安备 33010602011771号