This article shows the easiest way to audit commands to a MySQL database, assuming all content happens from an application. Now, this will use a lot of storage, and doubles the query load for each query, but it’s useful for when you know you want to capture the information of someone using the application.
The basic premise is simple. Logon to your nearest MySQL server and type the following:
SELECT CURRENT_USER(), USER();
Chances are the values are different. More on this later.
First, create a table:
CREATE TABLE `action` (
`user` varchar(77) NOT NULL default '',
`asuser` varchar(77) NOT NULL default '',
`db` varchar(64) NOT NULL default '',
`query` mediumtext NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Why varchar(77)? Because the mysql.user table puts a maximum of 16 characters for the username, and 60 characters for the …
[Read more]