本文使用的MySQL版本为8.0.28。
需要以root用户身份登陆才可以查看数据库编码方式
使用以下命令在命令行中登录MySQL
mysql -uroot -p
查看数据库默认字符集
输入以下命令,查看数据库默认字符集
SHOW VARIABLES LIKE 'character%';
显示结果
mysql> show variables like 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8mb3 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.05 sec)
其中,
character_set_client为客户端编码方式;
character_set_connection为建立连接使用的编码;
character_set_database数据库的编码;
character_set_results结果集的编码;
character_set_server数据库服务器的编码;
只要保证以上四个采用的编码方式一样,就不会出现乱码问题。
查看数据库默认排序方式
输入命令,查看数据库默认排序方式
SHOW VARIABLES LIKE 'collation%';
显示结果
mysql> show variables like 'collation%'; +----------------------+--------------------+ | Variable_name | Value | +----------------------+--------------------+ | collation_connection | utf8mb4_0900_ai_ci | | collation_database | utf8mb4_0900_ai_ci | | collation_server | utf8mb4_0900_ai_ci | +----------------------+--------------------+ 3 rows in set (0.01 sec)
查看数据库支持的引擎及默认引擎
输入命令,查看数据库默认排序方式
show engines;
显示结果
mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 9 rows in set (0.00 sec)
查看bin-log日志是否开启
输入命令
show variables like 'log_bin';
显示结果
mysql> show variables like 'log_bin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ 1 row in set (0.01 sec)
查看当前服务器使用的biglog文件及大小
mysql> show binary logs; +---------------+-----------+-----------+ | Log_name | File_size | Encrypted | +---------------+-----------+-----------+ | binlog.000001 | 180 | No | | binlog.000002 | 404 | No | | binlog.000003 | 91987129 | No | | binlog.000004 | 534315 | No | | binlog.000005 | 157 | No | +---------------+-----------+-----------+ 5 rows in set (0.00 sec)
查看详细的日志配置信息
show global variables like '%log%';
mysql数据存储目录
show variables like '%dir%';
查看binlog的目录
show global variables like "%log_bin%";
查看主服务器使用的biglog文件及大小
查看最新一个binlog日志文件名称和Position
show master status;
事件查询命令
IN 'log_name' :指定要查询的binlog文件名(不指定就是第一个binlog文件)
FROM pos :指定从哪个pos起始点开始查起(不指定就是从整个文件首个pos点开始算)
LIMIT [offset,] :偏移量(不指定就是0)
row_count :查询总条数(不指定就是所有行)
show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
查看 binlog 内容
show binlog events;
查看具体一个binlog文件的内容 (in 后面为binlog的文件名)
show binlog events in 'master.000003';
设置binlog文件保存事件,过期删除,单位天
set global expire_log_days=3;
删除当前的binlog文件
reset master;
删除slave的中继日志
reset slave;
删除指定日期前的日志索引中binlog日志文件
purge master logs before '2019-03-09 14:00:00';
删除指定日志文件
purge master logs to 'master.000003';
bin-log部分参考:https://blog.csdn.net/weixin_43628257/article/details/121356130
本站文章除注明转载/出处外,均为原创,若要转载请务必注明出处。转载后请将转载链接通过邮件告知我站,谢谢合作。本站邮箱:admin@only4.work
尊重他人劳动成果,共创和谐网络环境。点击版权声明查看本站相关条款。