How to clear logs from mysql and how to clear tables from mysql

Source: Internet
Author: User
If you want to disable binary mysql logs, you can. ini to the log-bin line comment out to clear the binary log, in mysql enabled the binary log state, log on to mysql as root after executing one of the following two commands: PURGEMASTERLOGSbefore2020-1-1; PURGEMASTER

If you want to disable binary mysql logs, you can. in ini, comment out the log-bin line to clear binary logs. when mysql enables binary logs, log on to mysql as the root user and execute one of the following two commands: purge master logs before '2017-1-1 '; PURGE MASTER

To disable binary mysql logs, comment out the log-bin line in my. ini.
To clear binary logs, log on to mysql as the root user and execute one of the following two commands when mysql enables binary logs:
Purge master logs before '2017-1-1 '; clears binary LOGS before a specified date
Purge master logs to 'mysql-bin.010 '; clears binary LOGS before the specified file number
Note that if you delete the mysql-bin.xxx file directly without running the command, the list of log files is still logged in the mysql-bin.index so that logs are cleared later, mysql logs cannot be cleared because the log files in the list cannot be found.
You can use mysqlbinlog.exe in the binlog to view the mysql binary log.
C: \> mysqlbinlog mysql-bin.000001
If the character set is set in my. ini, the following errors may occur:
Mysqlbinlog: unknown variable 'default-character-set = gbk'
Solve the problem with the -- no-defaults Parameter
C: \> mysqlbinlog -- no-defaults mysql-bin.000001
To clear *. err logs, stop the mysql database, cut or delete the file, and restart mysql to generate a new one.


2. Clear all content in a mysql table

Delete from table name;
Truncate table name;

The delete statement without the where parameter can delete all content in the mysql table. You can also use the truncate table to clear all content in the mysql table. In terms of efficiency, truncate is faster than delete, but after truncate is deleted, mysql logs are not recorded and data cannot be recovered.
The delete operation is like deleting all records in the mysql table one by one, and truncate is equivalent to retaining the structure of the mysql table and re-creating the table. All statuses are equivalent to new tables.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.