一.创建数据库
create database 数据库名
create database 数据库名 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
create database 数据库名 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
二.查看数据库
方法一:
shwo databases like '%dudu%';
方法二:
use dudu;(进入dudu这个数据库)
select database();
三.删除数据库
drop database dudu;
四.连接数据库
use dudu
五.查看当前数据库的表信息
show tables;
show tables in dudu_utf8;
六.删除用户
drop user ‘用户名可以为空’@'域名';
或者 delete from mysql.user where user='用户名' and host='域名';
flush privileges
七.创建用户
grant all on 库名.表名 TO ‘用户名’@'域名' IDENTIFIED by '密码'
create user ‘用户名’@‘域名’ identified by ‘密码’;
八.赋予用户权限
grant 权限 on 库名.表名 to ‘用户名’@域名;
九.查看用户权限
show grants for 用户名@域名;
十.收回权限
revoke 权限 on 库名.表名 from 用户名@域名;
十一.建表语句
方法1
create table 表名(列名 列中数据类型 not null,列名2 数据类型 default ‘0’);
方法2
create table ‘表名’(
列名 列中数据类型 not null,
列名 列中数据类型 default ‘0’
)ENGINE=InnoDB DEFAULT CHARSET=UTF8
十二.索引
1.删除索引
(1).主键索引
在有auto_increment时 alter table 表名 modify 列名 类型,drop primary key
在没有auto_increment时 alter table 表名 drop primary key;
(2).普通索引
alter table 表名 drop index 索引名;
2.添加索引
(1).主键索引
alter table 表名 add primary key(列名);
(2).普通索引
alter table 表名 add index 索引名(列名);
十三.增删改表的列
1.增加列名
alter table 表名 add 列名 类型 after 列名