Set a variable in mysql only once

I use classic ASP and MySQL (using PHP would not change the point of the question).

I need to set a variable on my home page:

SET block_encryption_mode = 'aes-256-cbc' 

I cannot set it as a global variable, as other users use the server and can use the default block_encryption_mode .

I know that I can use an instruction using ASP / PHP at the beginning of every web page, but it is like using too many resources; each user will execute the SET statement on each page ...

Is there a way to set a variable or execute some other SQL statement at the beginning of each session, for example, like an onstart event, like ASP? Or how can I achieve my goal without fulfilling a request for each user on every page that I have?

+5
source share
2 answers

It is safe to call SET on each page, since it is executed in queries in microseconds. There is literally no SET service calls on an already open connection.

If you cannot apply this parameter globally, I would not worry. Just set block_encryption_mode (along with collation and timezone ) immediately after receiving the database connection descriptor.

+2
source

You can use the 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.

You can also distinguish users from code as follows:

 IF (CURRENT_USER() = ' special_crypto_dude@localhost ') THEN SET SESSION block_encryption_mode = 'aes-256-cbc'; END IF; 
+3
source

Source: https://habr.com/ru/post/1270319/


All Articles