SQL command to display query history

I would like to show my executed sql command history in my MYSQL query browser. What is a sql statement to display history?

+93
mysql
Oct 19 '11 at 7:41
source share
6 answers

to try

cat ~/.mysql_history 

this will show you all the mysql commands running on the system

+139
Jun 10 '14 at 6:18
source share

For MySQL> 5.1.11 or MariaDB

  1. SET GLOBAL log_output = 'TABLE';
  2. SET GLOBAL general_log = 'ON';
  3. Look at the mysql.general_log table

If you want to output to the log file:

  1. SET GLOBAL log_output = "FILE";
  2. SET GLOBAL general_log_file = "/path/to/your/logfile.log"
  3. SET GLOBAL general_log = 'ON';

As mentioned in jeffmjack's comments, these settings will be forgotten until the next session if you do not edit the configuration files (for example, edit /etc/mysql/my.cnf and then restart to apply the changes).

Now, if you want, you can tail -f /var/log/mysql/mysql.log

More information here: Server system variables

+26
Sep 28 '13 at 2:07 on
source share

(Linux) Open terminal ctrl+alt+t run the command

  cat ~/.mysql_history 

you will get all previous mysql query history, enjoy :)

+21
Oct. 21 '15 at 6:52
source share

You will find him there

 ~/.mysql_history 

You will make it readable (without shoots) as follows:

 sed "s/\\\040/ /g" < .mysql_history 
+5
Apr 07 '19 at 10:03
source share

Take a look ~/.myslgui/query-browser/history.xml here you can find the latest queries made with mysql_query_browser (several days)

+2
Jan 26 '15 at 5:13
source share

You can look at the query cache: http://www.databasejournal.com/features/mysql/article.php/3110171/MySQLs-Query-Cache.htm , but it may not give you access to current queries and will be very successful -and -miss if it works (subtle pun)

But the MySQL Query Browser most likely maintains its own list of queries that it launches, outside of the MySQL engine. You will need to do the same in your application.

Edit: see dan m comment leading to the following: How to show the latest queries made in MySQL? looks great.

-one
Oct 19 2018-11-11T00:
source share