binlog日志

4.1 问题

启用binlog日志,具体要求如下:

启用binlog日志,把日志文件存放到系统的/mylog目录下,日志文件为db50
手动创建3个新的日志文件
删除编号3之前的日志文件

4.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:启用binlog日志

1)修改配置文件,并重启服务。

[root@dbsvr1 ~]# vim  /etc/my.cnf
[mysqld]
    server_id=1  //指定server_id
log-bin=/mylog/db50  //指定日志目录及名称                           
:wq
[root@dbsvr1 ~]# mkdir  /mylog   //创建目录
[root@dbsvr1 ~]# chown  mysql  /mylog   //修改所有者
[root@dbsvr1 ~]# systemctl  restart mysqld.service  //重启服务

2)查看日志信息

[root@dbsvr1 ~]# 
[root@localhost ~]# mysql -uroot -p123qqq...A //管理员登录
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show master status; //查看日志信息
+-------------+----------+--------------+------------------+-------------------+
| File        | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| db50.000001 |      154 |              |                  |                   |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>

3)手动创建3个新的日志文件

mysql>
mysql> flush logs;  //刷新日志
Query OK, 0 rows affected (0.14 sec)
mysql> flush logs; //刷新日志
Query OK, 0 rows affected (0.11 sec)
mysql> flush logs; //刷新日志
Query OK, 0 rows affected (0.12 sec)
mysql> system ls /mylog/  //查看日志文件
db50.000001  db50.000002  db50.000003  db50.000004  db50.index
mysql> 
mysql> show master status; //查看日志信息
+-------------+----------+--------------+------------------+-------------------+
| File        | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| db50.000004 |      154 |              |                  |                   |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>

4)删除编号3之前的日志文件

 mysql>
mysql> purge  master  logs  to  "db50.000003"; //删除日志
Query OK, 0 rows affected (0.05 sec)
mysql> system ls /mylog/    //查看日志文件
db50.000003  db50.000004  db50.index
mysql> 
mysql> system cat /mylog/db50.index //查看索引文件
/mylog/db50.000003
/mylog/db50.000004
mysql>
发布了252 篇原创文章 · 获赞 10 · 访问量 6633

猜你喜欢

转载自blog.csdn.net/weixin_45843450/article/details/105358305
今日推荐