145

I'm trying to track down a bug that's deleting rows in a mysql table.

For the life of me I can't track it down in my PHP code, so I'd like to work backwards by finding the actual mysql query that's removing the rows.

I logged in to phpmyadmin, but can't find a way to view the history of past sql operations.

Is there a way to view them in phpmyadmin?

chris1979
  • 2,667
  • 3
  • 16
  • 6
  • 2
    Can't you search your code for `DELETE` statements and debug that way? – webbiedave Jul 14 '10 at 14:43
  • Listen to baol and webbiedave. You should enable query logging is to see what's going, but then you still have to find where the SQL statements are coming from in your code. Start grepping for "delete", there can't be *that* many delete statements in your project. – joeynelson Jul 14 '10 at 14:50
  • yeah, i actually began by grepping for delete, but my eyes must be glossed over b/c none of the deletes seem problematic ... which is why i'm hoping the query log will help. thanks to you both for your help. – chris1979 Jul 14 '10 at 14:57
  • Check for any triggers in your database that might do the deletions as well – Mark Baker Jul 14 '10 at 15:36
  • possible duplicate of [where can I find mysql logs in phpmyadmin?](http://stackoverflow.com/questions/3039799/where-can-i-find-mysql-logs-in-phpmyadmin) – outis Sep 26 '12 at 19:12

14 Answers14

116

Ok, so I actually stumbled across the answer.

phpMyAdmin does offer a brief history. If you click on the 'sql' icon just underneath the 'phpMyAdmin' logo, it'll open a new window. In the new window, just click on the 'history' tab.

That will give you the last twenty or so SQL operations.

enter image description here

Community
  • 1
  • 1
chris1979
  • 2,667
  • 3
  • 16
  • 6
95

There is a Console tab at the bottom of the SQL (query) screen. By default it is not expanded, but once clicked on it should expose tabs for Options, History and Clear. Click on history.

The Query history length is set from within Page Related Settings which found by clicking on the gear wheel at the top right of screen.

This is correct for PHP version 4.5.1-1

alleyoopster
  • 1,194
  • 7
  • 6
  • 8
    Length is now under **Home | Settings | SQL queries | Query history length**. And maddeningly "Value must be equal or lower than 25!" – Bob Stein Apr 12 '16 at 21:17
  • Wonderful. I have always wanted that, assumed it was not possible, given "Get Autosaved Query" did something different. – Tuntable May 11 '21 at 02:01
  • You can see only the user query not all the queries – G M May 03 '23 at 15:40
70

You just need to click on console at the bottom of the screen in phpMyAdmin and you will get the Executed history:

enter image description here

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Samarth Saxena
  • 1,121
  • 11
  • 18
  • 1
    I was unable to find the page in the accepted answer (maybe it's from a different version), and this worked for me, thanks. – felwithe Aug 17 '18 at 14:02
  • 10
    This shows only Queries which were run by user from `phpmyadmin` itself. It is not show complete records of all performed queries. – Fusion Mar 20 '19 at 20:27
15

To view the past queries simply run this query in phpMyAdmin.

SELECT * FROM `mysql`.`general_log`

if it is not enabled, run the following two queries before running it.

SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
Community
  • 1
  • 1
Syed Waqas Bukhary
  • 5,130
  • 5
  • 47
  • 59
  • 8
    very usefull thanks. to anyone else SELECT * FROM `general_log` must be queried inside mysql table else you must include tablename: SELECT * FROM mysql.`general_log` – siggi_pop Aug 17 '17 at 12:59
  • #1146 - Table 'general_log' doesn't exist – xpredo Jan 15 '23 at 17:43
9

I don't think phpMyAdmin lets you do that, but I'd like to hear I'm wrong.

On the other hand you can enable query logging in MySQL: The General Query Log

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
baol
  • 4,362
  • 34
  • 44
8

Yes, you can log queries to a special phpMyAdmin DB table.

See SQL_history.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
blueyed
  • 27,102
  • 4
  • 75
  • 71
7

I am using phpMyAdmin Server version: 5.1.41.

It offers possibility for view sql history through phpmyadmin.pma_history table.

You can search your query in this table.

pma_history table has below structure:

enter image description here

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Dhinakar
  • 4,061
  • 6
  • 36
  • 68
3

You have to click on query window just below the phpMyAdmin logo, a new window will open. Just click on SQL History tab. There you can see history of SQL Queries.

Anurag Prashant
  • 995
  • 10
  • 31
3

OK so I know I'm a little late and some of the above answers are great stuff.

As little extra though, while in any PHPMyAdmin page:

  1. Click SQL tab
  2. Click 'Get auto saved query'

this will then show your last entered query.

Jackherer
  • 47
  • 1
  • 8
2

I may be wrong, but I believe I've seen a list of previous SQL queries in the session file for phpmyadmin sessions

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Apologies... I'd misread your question: the list in session is the list of previous statements issued through phpmyadmin, so it doesn't contain any SQL statements issued by your own PHP scripts, so probably not that helpful. – Mark Baker Jul 14 '10 at 15:28
2

Here is a trick that some may find useful:

For Select queries (only), you can create Views, especially where you find yourself running the same select queries over and over e.g. in production support scenarios.

The main advantages of creating Views are:

  • they are resident within the database and therefore permanent
  • they can be shared across sessions and users
  • they provide all the usual benefits of working with tables
  • they can be queried further, just like tables e.g. to filter down the results further
  • as they are stored as queries under the hood, they do not add any overheads.

You can create a view easily by simply clicking the "Create view" link at the bottom of the results table display.

0

you can run your past mysql with run /PATH_PAST_MYSQL/bin/mysqld.exe

it run your last mysql and you can see it in phpmyadmin and other section of your system.

notice: stop your current mysql version.

S F My English.

Omid Ahmadyani
  • 1,430
  • 13
  • 15
0

why dont you use export, then click 'Custom - display all possible options' radio button, then choose your database, then go to Output and choose 'View output as text' just scroll down and Go. Voila!

-5

There is a tool called Adminer which is capable of doing all phpmyadmin job packed in single tiny php file. http://www.techinfobit.com/how-to-import-export-database-without-any-extra-installation/