Home >Database >Mysql Tutorial >How Do I View and Secure MySQL Log Files?
How to See Log Files in MySQL
MySQL server maintains log files to record server activities, including query execution. Here's how you can view these logs:
Understanding MySQL Logs
MySQL maintains three main log files:
Enabling Log Files
By default, log files are disabled in MySQL. To enable them, edit the /etc/mysql/my.cnf configuration file and add the following lines:
For Error Log:
[mysqld_safe] log_error=/var/log/mysql/mysql_error.log [mysqld] log_error=/var/log/mysql/mysql_error.log
For General Query Log:
general_log_file = /var/log/mysql/mysql.log general_log = 1
For Slow Query Log:
log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 2 log-queries-not-using-indexes
Viewing Log Files
Once log files are enabled, they will be located in the /var/log/mysql directory. You can view them using a text editor such as:
vi /var/log/mysql/mysql.log
Security Considerations
Log files may contain sensitive information such as usernames and passwords. To secure these logs, consider the following:
Note
The above is the detailed content of How Do I View and Secure MySQL Log Files?. For more information, please follow other related articles on the PHP Chinese website!