导航

MySQL日常维护指南

Posted on 2023-01-05 13:52  十斗米  阅读(225)  评论(0编辑  收藏  举报

一、常用命令

1、查看数据库默认编码

show variables like 'character%';  

show variables like 'collation%';

2、启动停止数据库

/etc/init.d/mysql start (stop) 

3、创建数据库

create database if not exists 数据库名 default charset gbk collate gbk_chinese_ci;

create database if not exists 数据库名 default charset gbk collate gbk_bin;

create database if not exists 数据库名 default charset utf8mb4 collate utf8mb4_unicode_ci;

4、创建数据表

create table 表名 (

    ......

) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci;

5、查看表当前字符集
show cereate table 表名;
6、查看字符集的排序规则
show collation
7、查看表类型
show create table tablename
8、创建用户并授权
grant all on 数据库名.* to '用户名'@'%' identified by '密码';
flush privileges;
create user '用户名'@'%' identified by '密码';
grant all on 数据库名.* to '用户名'@'%';
flush privileges;
9、权限撤销
revoke 权限名 on 数据库名.表名 from 用户名@主机名;
10、查看for update超时时间设置
show global variables like "%timeout%";
set global innodb_lock_wait_timeout = 10; 
11、查看正在锁和等待锁的事务
select * from information_schema.innodb_locks;
select * from information_schema.innodb_lock_waits;
 
二、概念解释
1、什么是collate?
2、engine=lnnoDB 和 MyISAM的区别?