chris1979
chris1979

Reputation: 2717

Is there a way to view past mysql queries with phpmyadmin?

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?

Upvotes: 149

Views: 222083

Answers (14)

Syed Waqas Bukhary
Syed Waqas Bukhary

Reputation: 5340

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';

Upvotes: 17

SmallOutside.com
SmallOutside.com

Reputation: 21

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.

Upvotes: 2

baol
baol

Reputation: 4358

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

Upvotes: 9

Samarth Saxena
Samarth Saxena

Reputation: 1191

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

Upvotes: 76

blueyed
blueyed

Reputation: 27858

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

See SQL_history.

Upvotes: 8

Dhinakar
Dhinakar

Reputation: 4151

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

Upvotes: 7

Display Name
Display Name

Reputation: 1

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!

Upvotes: 0

Omid Ahmadyani
Omid Ahmadyani

Reputation: 1450

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.

Upvotes: 0

chris1979
chris1979

Reputation: 2717

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

Upvotes: 117

Jackherer
Jackherer

Reputation: 47

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.

Upvotes: 3

alleyoopster
alleyoopster

Reputation: 1214

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

Upvotes: 97

Nishant Kumar
Nishant Kumar

Reputation: 1

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/

Upvotes: -5

Anurag Prashant
Anurag Prashant

Reputation: 1014

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.

Upvotes: 3

Mark Baker
Mark Baker

Reputation: 212412

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

Upvotes: 2

Related Questions