FreezeJ' Blog

mysql常用命令

2022-07-14

常用的命令,总是忘记纯手敲不出来,记录一下。

创建数据库并授权

# 创建数据库
create database DBNAME default charset utf8mb4 COLLATE utf8mb4_unicode_ci;

# 创建用户
GRANT ALL ON DBNAME.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD';

# 刷新权限
flush privileges;

清除binlog

# 删除某个时间前的binlog(临时释放空间)
purge binary logs before '2022-01-01 00:00:00';

删除空账号

DELETE FROM mysql.user WHERE password='' or user='';
Tags: Mysql