When I use client libraries like MySQLdb
or oursql
, how can I know if it's using prepared statements or not?
Is there anyway I can tell the difference on the server side? Maybe by looking into some kind of logs?
EDIT: I'm using MySQL5.1
Assuming the client has permission to use stored procs, you must use logging of some form.
If you have control of the client, you can have the client log all requests and examine that log.
If you don't have control of the client, you can turn on detailed logging at the db server and examine the SQL statements vs client id.
If you don't have that kind of control over the database, you can "log" from within the stored proc(s) by modifying them to also insert into a log table the user making the request and the timestamp etc.
These options are presented roughly in the order of preference.
Read this link for what's involved in turning on General Query Logging. A précis from that link:
The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients.
As of MySQL5.1, you can enable general_log
at runtime: SET GLOBAL general_log = 1
And use SELECT @@general_log_file
to locate the log file.
You need to enable the MySQL general_log table/feature. You would see PREPARE statements in there from clients that are using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With