How to automatically call a query for every new connection in MySQL?

Is it possible to set or initialize a query in MySQL for each new connection?

Whenever a connection is created, will it automatically invoke a procedure or query of choice?

Any script or config parameter for this?

+5
source share
2 answers

You can check init_connect variable:

The string that will be executed by the server for each connected client. A string consists of one or more SQL statements, separated by semicolons. For example, each client session begins with a default with autosave enabled.

http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_init_connect

+10
source

If you have not only the mysql-client tool, but also an additional application layer, there is more jedi style :) You can create a simple decorator for your connector class that will fulfill some requests when creating an instance of the instance (in the constructor) / connect.

Hope this helps

+3
source

All Articles