SQL语法基本操作
查看库名:show databases;
查看表名:show tables;
查看当前使用的库:show database();
使用库:use 数据库名;
创建数据库:create database 数据库名;
创建表,字段
create table employee(
id int,
name varchar(20),
gender varchar(20)
);
查看表的信息
show create table 表名;
删表
drop table 表名;
删除库
drop database 库名;
添加列
alter table 表名 add 列名 类型(长度);
alter table data add name varchar(20);
修改列长度
alter table 表名 modify 列名 类型(长度);
修改现有列的名称
alter table 表名 change 旧列名 新列名 类型(长度)
删除列
alter table 表名 drop column 列名
查表中数据
select * from 表名;
添加数据
insert into 表名 ( 列名,列名,列名)values(值,值,值);
insert into student(id,name,age)values(1,"张三",23);
select id,name from student
delete from 表名 where id=1;
update 表名 set 列名=值,列名=值.. where
update student set id=2 where name='lisi'
将字段name='lisi’的字段更新id=2
创建表,自带主键
create table news(
id int primary key auto_increment,
title varchar(200),
type varchar(10)
);
insert into news(title,type)values("today is sunshine","111");
查看MySQL链接数
show full processlist;

浙公网安备 33010602011771号