//连接数据库
mysql -hIP -P端口 -u用户名 -p密码
//查询实例有哪些用户
SELECT user,host FROM mysql.user;
//查询用户有哪些权限
select * from mysql.user where user='xx'
//查询用户对哪些库表有权限
show grants for 'xx'
//创建用户
create user xx identified by 'yyy'
//授权
grant all privileges on 数据库.* to 用户@'%' identified by '密码'
GRANT SELECT, INSERT, UPDATE, DELETE ON 数据库.tbname TO '用户'@'%' IDENTIFIED BY '密码';
查看所有进程
show full processlist
//查看binlog目录
SHOW VARIABLES LIKE '%log_bin%'
//查看binlog过期时间
show variables like 'expire_logs_days';
//查看每个binlog文件最大大小,超过会重新创建一个binlog文件
show variables like 'max_binlog_size'
//查看执行语句使用索引信息
exlain xxxsql
//删除binlog日志 删除000340之前的不包含000340
PURGE MASTER LOGS TO 'bin.000340'
//数据库迁移
mysqldump -hIP地址 -u用户 -p密码 -P 端口 --single-transaction --default-character-set=utf8mb4 --skip-add-locks --master-data=2 --set-gtid-purged=OFF 库 表1 表2 | gzip > /data/sqldata/库.sql.gz &
mysql常用命令
于 2022-09-13 10:55:17 首次发布