Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search in the mysql command history

Tags:

mysql

The mysql command-line client supports a history (you can use the cursor-keys to access and navigate it), but is there a way to access it (for example) in bash?

In bash you can do:

history | grep "command"

Is there something similar in mysql?

like image 403
Roland Seuhs Avatar asked Dec 02 '14 08:12

Roland Seuhs


People also ask

Does MySQL have history?

On Unix, mysql writes the statements to a history file. By default, this file is named . mysql_history in your home directory.

How do I view MySQL transaction logs?

The transaction log in MySQL is not enabled by default and must be enabled in order to log transactions. To determine if the transaction log is active you can use the “show binary logs” statement: SHOW BINARY LOGS; If binary logging is disabled you will receive an error stating “you are not using binary logging”.

How do I view MySQL workbench history?

Show activity on this post. From the bottom panel, change "Action Output" to "History" and then choose the appropriate date. Alternatively, the SQL statement history is stored in text files under two locations: sql_history/yyyy-mm-dd e.g., sql_history/2015-04-01: Full Workbench SQL history for all MySQL connections.


Video Answer


4 Answers

You may use Ctrl+R to search the history, as in bash.

like image 63
Steve Avatar answered Oct 03 '22 08:10

Steve


Usually this lists up all MySQL commands that have been used:

less ~/.mysql_history
like image 23
Florian Blum Avatar answered Oct 03 '22 08:10

Florian Blum


so, in mysql you can use:

system grep "command" ~/.mysql_history

like image 27
drpes Avatar answered Oct 03 '22 08:10

drpes


Open the file in vim editor

vi ~/.mysql_history

then you can search the pattern with / by entering you text.

like image 36
Vishvajit Pathak Avatar answered Oct 03 '22 10:10

Vishvajit Pathak