Home >Database >Mysql Tutorial >How Can I Enable and Access MySQL Log Files?

How Can I Enable and Access MySQL Log Files?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-04 17:31:11270browse

How Can I Enable and Access MySQL Log Files?

Where to Find and Read MySQL Log Files

By default, MySQL does not generate extensive log files. However, you can enable and view specific log types to track server activities.

Enabling and Reading Log Files

To enable and read MySQL log files, follow these steps:

  1. Enable error log by adding log_error=/var/log/mysql/mysql_error.log to /etc/mysql/my.cnf.
  2. Enable general query log by adding general_log_file=/var/log/mysql/mysql.log and general_log=1 to /etc/mysql/my.cnf.
  3. Enable slow query log by adding log_slow_queries=/var/log/mysql/mysql-slow.log, long_query_time=2, and log-queries-not-using-indexes to /etc/mysql/my.cnf.
  4. Restart MySQL using service mysql restart.

Log File Security

Sensitive information, such as usernames and passwords, is typically logged in encrypted form. By default, MySQL stores logs in the /var/log/mysql/ directory, which is restricted to privileged users.

Other Methods for Viewing Logs

Besides viewing logs directly from files, you can also use MySQL client commands to enable logs at runtime:

  • SET GLOBAL general_log = 'ON';
  • SET GLOBAL slow_query_log = 'ON';

You can find more information on MySQL logging and security in the official MySQL documentation.

The above is the detailed content of How Can I Enable and Access MySQL Log Files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn