MySQL --> Enable general log and move it to another drive/device - mysql

I need to enable mysql general log and to move it to another drive/device that i've in my system by nsf!
So, i've enable it in my.cnf:
general_log = 1
general_log_file = /nsf/directory
expire_logs_days = 7
I guess the log can't write directly in that directory right?
How can I do this?
I've think in another solution, like to write logs in /var/log/ and to rotate them and them move it to nfs? Or do some script to run in cronjob?

As per my understanding you can't generate log in nfs but yes you can move to nfs by script after logging in any server partition.
you can schedule a cron, which will either purge logs after an interval or copy in another file and purge log file as per your requirement.
Even you can generate general query logs in table instead of file and analyze through sql query in better way, also archive old logs from table and remove from table.
So check your requirement and take decision accordingly.
Note: This is for your information that expire_logs_days is a variable for binary log not general query log.

Related

How to remove MySql bin logs automatically when slave completed sync ?

I have two mysql servers one is mater(mysqlone) and another is slave(mysql2) have replication
i want to delete log file automatically in master when slave completes the reading of logs from master, without script is there any options and variables in mysql.
Simple answer - No. You`ll have to make/get something if you want it automated.
Are you aware of PURGE BINARY LOGS?
It is not too difficult to automate this using a script.

How to enable MySQL Query Log in version 5.6.19?

The answers to this similar question are outdated:
How to enable MySQL Query Log?
"How do I enable the MySQL function that logs each SQL query statement received from clients and the time that query statement has submitted? How do I analyse the log?"
I've been unable to locate any advice that actually works.
The manual is useless in this area. Overly verbose and goes on and on about WHAT the log is and WHY you'd want to use it, but no accurate info on HOW TO TURN IT ON:
http://dev.mysql.com/doc/refman/5.7/en/query-log.html
Duh. When using MySQL Workbench on Windows, the "Administration - Server Status" tab will still say that the General Log is OFF, even though files are being created in c:\ProgramData\MySQL\MySQL Server 5.6\data
I added this to the my.cnf:
general-log = 1
general_log_file = "general.log"
Well I certainly did not make use of general-log yet, but that is mostly due to the fact that practically every server I run uses replication either for HA/LB or backup purposes. With replication set you also get the bin-log, which essentialy does what you need (with a small help from mysqlbinlog tool). I've used it in couple occasions to restore the database to a given point in time (using mysql dump from time X and replay of binlog file X - Y)
for that, you might be interested in ie.:
log-bin = /var/lib/mysql/binlog/bin.log
log-bin-index = /var/lib/mysql/binlog/bin.index
expire_logs_days = 1
max_binlog_size = 1G

In MySQL, how can I delete/flush/clear all the logs that are not necessary?

I have tried several commands (FLUSH LOGS, PURGE MASTER) but none deletes the log files (when previously activated) or the log tables (mysql/slow_log.CSV and mysql/general_log.CSV and their .frm and .CSM counterparts).
SHOW BINARY LOGS returns "You are not using binary logging".
Edit: I found this simple solution to clear the table logs (but not yet the file logs using a mysql command):
TRUNCATE mysql.general_log;
TRUNCATE mysql.slow_log;
FLUSH LOGS just closes and reopens log files. If the log files are large, it won't reduce them. If you're on Linux, you can use mv to rename log files while they're in use, and then after FLUSH LOGS, you know that MySQL is writing to a new, small file, and you can remove the old big files.
Binary logs are different. To eliminate old binlogs, use PURGE BINARY LOGS. Make sure your slaves (if any) aren't still using the binary logs. That is, run SHOW SLAVE STATUS to see what binlog file they're working on, and don't purge that file or later files.
Also keep in mind that binlogs are useful for point-in-time recovery in case you need to restore from backups and then reapply binlogs to bring the database up to date. If you need to use binlogs in this manner, don't purge the binlogs that have been written since your last backup.
If you are on amazon RDS, executing this twice will do the trick:
PROMPT> CALL mysql.rds_rotate_slow_log;
PROMPT> CALL mysql.rds_rotate_general_log;
Source: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html
It seems binary logging is not enabled in your server .And i guess you want to delete the old log files which were used/created at the time of binary logging is enabled . you can delete them manually using 'rm' command if you want . if you want to enable the binary logging you can do the same by updating the configuaration file ( but it needs restart of the server if it is already running) . You can refer below links.
http://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#option_mysqld_log-bin
http://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#sysvar_log_bin

Is it safe to delete replication relay-bin files?

I've got a small database, around 50mb. It's a master replicating to a remote server. I noticed that the relay-bin files total to over 5GB. Is it safe to delete them?
I think a better answer is relay logs can be 'deleted' but mysql should manage it automatically.
One way to do this is to check for the value of relay_log_purge.
It should be set to 1 if you want mysql to manage them:
set global relay_log_purge=1;
You would probably need to flush the logs:
flush logs;
This does not affect the binary logs.
Maybe try to resync your master and slave.
If possible, cleanup the slave by running a
reset slave
it will purge all relay binary logs.
Then set the replication again with change master to ...
You may have too much lag between your master and slave.
From the MySQL manual:
The SQL thread automatically deletes each relay log file after it has
executed all events in the file and no longer needs it. There is no
explicit mechanism for deleting relay logs because the SQL thread
takes care of doing so. However, FLUSH LOGS rotates relay logs, which
influences when the SQL thread deletes them.
No, do not delete the relay-bin files manually. What you can do is to purge the binary files using MySQL commands. See the MySQL 5.0 Manual for more on the PURGE BINARY LOGS command.

Mysql Replication- Master-bin log files are not updated

I am new in Mysql Replication,
My problem is : When i Give SHOW SLAVE STATUS Command on Slave, Master-bin-log files are not updated, i reset it and update the Master-bin-log file with the command CHANGE MASTER TO MASTER , still master-bin-log files are not updated when i check with the SHOW SLAVE STATUS command.
Addition to that, at the appropriate path Master-bin-log files are generated but not updated.
Please help me get out of this problem...
Thanks in advance!!!!
Riddhi
From what you are saying, I assume that you want binary logging on the slave.
I think the problem stems from something that has bitten me many times.
Please add this to /etc/my.cnf on the slave:
[mysqld]
log-slave-updates
Without this, the data is updated from the relay logs but the transaction is not recorded in the slave's binary logs.
Adding this is crucial, especially if you plan to use the slave as a master someday.