Izhuceul 发表于 2018-10-9 08:55:47

MySQL数据库总结

  引擎
  查看MySQL默认引擎:
  show variables like '%storage_engine%';
  查看表引擎:
  show table status from 数据库名;
  修改表引擎
  alter table 表名 engine=InnoDB;
  创建时直接定义引擎
  create table 表名() engine=InnoDB;
  编码
  数据库中查看字符串编码:
  show variables like'character%';
  修改数据库中表的编码:
  alter table 表名 convert to character set utf8;
  查看数据库中表的编码(显示完整的建表语句)
  show create table 表名
  创建数据库时指定数据库的字符集:
  create database 数据库名 character set utf8;
  创建数据表时指定数据表的编码格式:
  create table tb_books (
  name varchar(45) not null,
  price double not null,
  bookCount int not null,
  author varchar(45) not null ) default charset = utf8;
  修改字段编码格式:
  alter tablechange    character set utf8;
  增删改查
  增加:
  insert into 数据库名 values(内容)
  insert into 数据库名(字段) values(内容)
  删除:
  delete from 表名 where 字段
  改写:

  update 表名 set 更改内容(name=1) where>  查 :
  select * from 表名
  修改表结构
  alter table 表名 change 旧字段名 新字段名 字段类型
  索引
  1.普通索引
  2.唯一索引
  3.全文索引
  4.单列索引
  5.多列索引
  6.空间索引
  7.主键索引
  8.组合索引
  普通索引:仅加速查询
  唯一索引:加速查询 + 列值唯一(可以有null)
  主键索引:加速查询 + 列值唯一 + 表中只有一个(不可以有null)
  组合索引:多列值组成一个索引,专门用于组合搜索,其效率大于索引合并
  全文索引:对文本的内容进行分词,进行搜索
  创建表+索引:
  create table 表名(
  nid int not null auto_increment primary key,
  name varchar(32) not null,
  email varchar(64) not null,
  extra text,
  index 索引名 (字段名)
  )
  创建索引
  create index 索引名 on 表名(字段名)
  删除索引:
  drop 索引名 on 表名;
  查看索引
  show index from 表名
  修改数据库root密码:
  mysql> set password for 用户名@localhost = password('新密码');
  mysqladmin -u用户名 -p旧密码 password 新密码
  权限
  创建用户(授权)
  grant 权限 on 数据库.表 to '用户名'@'登录主机' ;
  撤销权限
  remove 权限 on 数据库.表 from '用户名'@'登录主机;
  查看权限:
  show grants;//自己
  show grants for 用户名称@主机名称;

页: [1]
查看完整版本: MySQL数据库总结