Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4463184
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: Mysql/postgreSQL

2011-08-04 13:47:25

接着上节,这节中学习的是 日志文件-二进制文件







实验操作

1.关闭数据库
  1. ywx@ywx:/opt/mysql5151$ sudo ./bin/mysqladmin --defaults-file=./my.cnf shutdown
  2. [sudo] password for ywx:
  3. 110804 13:17:38 mysqld_safe mysqld from pid file /opt/mysql5151/data/ywx.pid ended
  4. [1]+ Done ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx --log-error=/tmp/mysql3306.err
  5. ywx@ywx:/opt/mysql5151$

2.设置二进制日志文件

  1. ywx@ywx:/opt/mysql5151$ ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx --log-bin=/tmp/1.0000000001 --log-bin-index=/tmp/logbin.index --max-binlog-size=10M --binlog-do-db=test &
  2. [1] 11150
  3. ywx@ywx:/opt/mysql5151$ 110804 13:19:40 mysqld_safe Logging to '/opt/mysql5151/data/ywx.err'.
  4. 110804 13:19:40 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5151/data
  5. ywx@ywx:/opt/mysql5151$

3. 查看启动数据库没有

  1. ywx@ywx:/opt/mysql5151$ ps -ef | grep mysql
  2. ywx 11150 8299 0 13:19 pts/0 00:00:00 /bin/sh ./bin/mysqld_safe --defaults-
  3. file=./my.cnf --user=ywx --log-bin=/tmp/1.0000000001 --log-bin-index=/tmp/logbin.index --
  4. max-binlog-size=10M --binlog-do-db=test

4.查看指定生成的文件

  1. ywx@ywx:/tmp$ ls
  2. 1.000001 orbit-gdm ssh-pogBWO1710
  3. keyring-qBd4di orbit-ywx virtual-ywx.E2YEf7
  4. logbin.index pulse-PKdhtXMmr18n VMwareDnD
  5. mysql3306.err pulse-vW0CAOZ7PouR vmware-root
  6. mysql.sock rst.txt vmware-ywx
  7. ywx@ywx:/tmp$
  8. ywx@ywx:/tmp$ cat ./logbin.index 这个文件存储的 日志文件数量
  9. /tmp/1.000001

5. 显示 二进制日志

  1. mysql> show binary logs;
  2. +----------+-----------+
  3. | Log_name | File_size |
  4. +----------+-----------+
  5. | 1.000001 | 106 |
  6. +----------+-----------+
  7. 1 row in set (0.00 sec)
如果我重新启动,将会有2个二进制文件
  1. ywx@ywx:/opt/mysql5151$ ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx --log-
  2. bin=/tmp/1.0000000001 --log-bin-index=/tmp/logbin.index --max-binlog-size=10M --binlog-do
  3. -db=test &

  4. mysql> show binary logs;
  5. +----------+-----------+
  6. | Log_name | File_size |
  7. +----------+-----------+
  8. | 1.000001 | 125 |
  9. | 1.000002 | 106 |
  10. +----------+-----------+
  11. 2 rows in set (0.00 sec)

  1. mysql> system cat /tmp/logbin.index
  2. /tmp/1.000001
  3. /tmp/1.000002


6.查看 最大10M
--max-binlog-size=10M

  1. mysql> show variables like '%max_binlog%';
  2. +-----------------------+------------+
  3. | Variable_name | Value |
  4. +-----------------------+------------+
  5. | max_binlog_cache_size | 4294963200 |
  6. | max_binlog_size | 10485760 |
  7. +-----------------------+------------+
  8. 2 rows in set (0.00 sec)

7. 切换日志,产生一个新的日志 flush

  1. mysql> flush logs;
  2. Query OK, 0 rows affected (0.03 sec)
  3. mysql> purge binary logs to '1.000003';

8.删除超过5天的日志

  1. mysql> show variables like '%expire%';
  2. +------------------+-------+
  3. | Variable_name | Value |
  4. +------------------+-------+
  5. | expire_logs_days | 0 |
  6. +------------------+-------+
  7. 1 row in set (0.00 sec)

  设置天数
  1. mysql> set global expire_logs_days=5;
  2. Query OK, 0 rows affected (0.00 sec)

  1. mysql> show variables like '%expire%';
  2. +------------------+-------+
  3. | Variable_name | Value |
  4. +------------------+-------+
  5. | expire_logs_days | 5 |
  6. +------------------+-------+
  7. 1 row in set (0.00 sec)

  8. mysql>

8.删除所有日志,然后重新生成一个日志

 reset master;


9 删除部分日志, purge  master logs;

  如果不清楚命令, 查看 ? purge



阅读(632) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~