Last active
August 29, 2015 14:15
-
-
Save carltondickson/dd291d5897d770c554c7 to your computer and use it in GitHub Desktop.
Log MySQL output to file without restart - FILE and TABLE approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/a/20485975/682754 | |
# Log to file | |
#### Turn on and configure | |
SET global log_output = 'FILE'; | |
SET global general_log_file='/tmp/mysql_general.log'; | |
SET global general_log = 1; | |
#### Turn off | |
SET global general_log = 0; | |
# Log to table | |
CREATE TABLE `slow_log` ( | |
`start_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
`user_host` MEDIUMTEXT NOT NULL, | |
`query_time` TIME NOT NULL, | |
`lock_time` TIME NOT NULL, | |
`rows_sent` INT(11) NOT NULL, | |
`rows_examined` INT(11) NOT NULL, | |
`db` VARCHAR(512) NOT NULL, | |
`last_insert_id` INT(11) NOT NULL, | |
`insert_id` INT(11) NOT NULL, | |
`server_id` INT(10) UNSIGNED NOT NULL, | |
`sql_text` MEDIUMTEXT NOT NULL, | |
`thread_id` BIGINT(21) UNSIGNED NOT NULL | |
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'; | |
CREATE TABLE `general_log` ( | |
`event_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
`user_host` MEDIUMTEXT NOT NULL, | |
`thread_id` BIGINT(21) UNSIGNED NOT NULL, | |
`server_id` INT(10) UNSIGNED NOT NULL, | |
`command_type` VARCHAR(64) NOT NULL, | |
`argument` MEDIUMTEXT NOT NULL | |
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'; | |
#### Enable Query logging on the database | |
SET GLOBAL general_log = 1; | |
SET GLOBAL log_output = 'table'; | |
#### View the log | |
SELECT * FROM mysql.general_log | |
#### Disable Query logging on the database | |
SET GLOBAL general_log = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment