How to find history of commands run on mysql?

by raphael_tillman , in category: MySQL , 7 months ago

How to find history of commands run on mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , 7 months ago

@raphael_tillman 

To find the history of commands run on MySQL, you can use the MySQL command line client or enable the general query log. Here are the steps for both methods:

  1. Using MySQL Command Line Client: Open the MySQL command line client by running the following command in your terminal: mysql -u [username] -p Replace [username] with your MySQL username and enter your password when prompted. Once you are inside the MySQL command line client, you can view the history of previously executed commands by pressing the 'Up' arrow key on your keyboard. Use the arrow keys to browse through the command history.
  2. Enabling General Query Log: Open your MySQL configuration file. The location of the file will depend on your system setup. On Linux, the MySQL configuration file is usually located at /etc/mysql/my.cnf or /etc/my.cnf. Locate the [mysqld] section in the configuration file. Add the following line within the [mysqld] section: general_log = 1 Save the configuration file and restart the MySQL service for the changes to take effect. On Linux, you can restart the MySQL service with the command: sudo service mysql restart. The general query log file will be created and will log all SQL statements executed on the MySQL server. To access the log file and view the command history, you can open the file with any text editor or use the tail command in the terminal. The default location of the log file is: On Linux: /var/log/mysql/mysql.log or /var/log/mysql.log


Note: Enabling the general query log can have an impact on performance and disk space usage, so use it cautiously and consider disabling it once you have retrieved the required information.