0

I must be going nuts here, but I could swear I read about a configuration option in MySQL that will run the defined SQL statement on every successful connection to the database, with the cavet that it would not run for root or those with a certain privilege to prevent shutting the server down with a bad sql statement here.

Was I imagining things or do folks know of such a parameter?

I have dug though the MySQL documents and so far I'm not turning up with any success.

Note, this is NOT for the client supplied sql statements, but instead for a statement that the server itself runs regardless of who connects and for what task, and great for tracking who connects with what account if general_log was not enabled for some reason or special handling is required.

migrated from stackoverflow.com Jan 12 at 10:23

This question came from our site for professional and enthusiast programmers.

2

Found it.

The parameter is named init_connect and will run the defined sql for each connection, except for those with the super privilege. No result sets are produced by this though so selects are not recommended for this.

The big cavet I see here though is that access to the objects is based on the connecting user's permissions, which make sense.. though it does make an 'autorun' style stored procedure harder to implement as that procedure needs to be accessible to everyone, which could cause problems if it's written with the expectation to be executed only once per connection.

  • Interesting... what is a good use case for this? – dmikester1 Jan 11 at 22:39
  • It's init_command, not init_connect. – Barmar Jan 11 at 22:39
  • 1
    @dmikester1 You can use it for things like setting the timezone. – Barmar Jan 11 at 22:40
  • Oh, this is different from the mysql client init_command option. – Barmar Jan 11 at 22:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.