Finding history of commands in mysql of ubuntu

When i press up arrow key on keyboard after logging in mysql by root, i can see what all commands i ran. I want to get the commands which i ran long time ago. So how can i show that all commands in a single file.


Solution 1:

By default, the MySQL history file is $HOME/.mysql_history.

You should be able to print it's contents using:

cat $HOME/.mysql_history

If you've run mysql using sudo, then it shall be:

sudo -i bash -c "cat \$HOME/.mysql_history"

or simply (assuming default $HOME):

sudo cat /root/.mysql_history