接着上节,这节中学习的是 日志文件-二进制文件
实验操作
1.关闭数据库
- ywx@ywx:/opt/mysql5151$ sudo ./bin/mysqladmin --defaults-file=./my.cnf shutdown
-
[sudo] password for ywx:
-
110804 13:17:38 mysqld_safe mysqld from pid file /opt/mysql5151/data/ywx.pid ended
-
[1]+ Done ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx --log-error=/tmp/mysql3306.err
-
ywx@ywx:/opt/mysql5151$
2.设置二进制日志文件
- 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 &
-
[1] 11150
-
ywx@ywx:/opt/mysql5151$ 110804 13:19:40 mysqld_safe Logging to '/opt/mysql5151/data/ywx.err'.
-
110804 13:19:40 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5151/data
-
ywx@ywx:/opt/mysql5151$
3. 查看启动数据库没有
- ywx@ywx:/opt/mysql5151$ ps -ef | grep mysql
-
ywx 11150 8299 0 13:19 pts/0 00:00:00 /bin/sh ./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
4.查看指定生成的文件
- ywx@ywx:/tmp$ ls
-
1.000001 orbit-gdm ssh-pogBWO1710
-
keyring-qBd4di orbit-ywx virtual-ywx.E2YEf7
-
logbin.index pulse-PKdhtXMmr18n VMwareDnD
-
mysql3306.err pulse-vW0CAOZ7PouR vmware-root
-
mysql.sock rst.txt vmware-ywx
-
ywx@ywx:/tmp$
-
ywx@ywx:/tmp$ cat ./logbin.index 这个文件存储的 日志文件数量
-
/tmp/1.000001
5. 显示 二进制日志
- mysql> show binary logs;
-
+----------+-----------+
-
| Log_name | File_size |
-
+----------+-----------+
-
| 1.000001 | 106 |
-
+----------+-----------+
-
1 row in set (0.00 sec)
如果我重新启动,将会有2个二进制文件- 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 &
-
mysql> show binary logs;
-
+----------+-----------+
-
| Log_name | File_size |
-
+----------+-----------+
-
| 1.000001 | 125 |
-
| 1.000002 | 106 |
-
+----------+-----------+
-
2 rows in set (0.00 sec)
- mysql> system cat /tmp/logbin.index
-
/tmp/1.000001
-
/tmp/1.000002
6.查看 最大10M --max-binlog-size=10M
- mysql> show variables like '%max_binlog%';
-
+-----------------------+------------+
-
| Variable_name | Value |
-
+-----------------------+------------+
-
| max_binlog_cache_size | 4294963200 |
-
| max_binlog_size | 10485760 |
-
+-----------------------+------------+
-
2 rows in set (0.00 sec)
7. 切换日志,产生一个新的日志 flush
- mysql> flush logs;
-
Query OK, 0 rows affected (0.03 sec)
-
mysql> purge binary logs to '1.000003';
8.删除超过5天的日志
- mysql> show variables like '%expire%';
-
+------------------+-------+
-
| Variable_name | Value |
-
+------------------+-------+
-
| expire_logs_days | 0 |
-
+------------------+-------+
-
1 row in set (0.00 sec)
设置天数
- mysql> set global expire_logs_days=5;
-
Query OK, 0 rows affected (0.00 sec)
- mysql> show variables like '%expire%';
-
+------------------+-------+
-
| Variable_name | Value |
-
+------------------+-------+
-
| expire_logs_days | 5 |
-
+------------------+-------+
-
1 row in set (0.00 sec)
-
-
mysql>
8.删除所有日志,然后重新生成一个日志
reset master;
9 删除部分日志, purge master logs;
如果不清楚命令, 查看 ? purge
阅读(632) | 评论(0) | 转发(0) |