I've found that session variables have priority over global variables.
Is it possible to apply global variables which is set by "set global" query to opened session so make local one to same with global one?
Or, is there any way to wait all opened session finish their tasks, and make sleeping session to reconnect?
You can reset any session variable back to its global variable equivalent whenever you want, you don't have to reconnect.
e.g.
mysql> SET ##session.foreign_key_checks=0;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT ##global.foreign_key_checks,##session.foreign_key_checks;
+-----------------------------+------------------------------+
| ##global.foreign_key_checks | ##session.foreign_key_checks |
+-----------------------------+------------------------------+
| 1 | 0 |
+-----------------------------+------------------------------+
1 row in set (0.00 sec)
mysql> SET ##session.foreign_key_checks=##global.foreign_key_checks;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT ##global.foreign_key_checks,##session.foreign_key_checks;
+-----------------------------+------------------------------+
| ##global.foreign_key_checks | ##session.foreign_key_checks |
+-----------------------------+------------------------------+
| 1 | 1 |
+-----------------------------+------------------------------+
1 row in set (0.00 sec)
Yes, session variables are prioritized to use over global variables, and there are 2 kinds of global and session variables.
Like "transaction_isolation", one can automatically set global variables to session variables after changing global variables and reconnecting (logging out and logging in) MySQL.
Like "wait_timeout", one cannot automatically set global variables to session variables after changing global variables and reconnecting (logging out and logging in) MySQL.
For example about "transaction_isolation", REPEATABLE-READ is the default value for "transaction_isolation" global and session variables as shown below:
mysql> SELECT ##global.transaction_isolation, ##session.transaction_isolation;
+--------------------------------+---------------------------------+
| ##global.transaction_isolation | ##session.transaction_isolation |
+--------------------------------+---------------------------------+
| REPEATABLE-READ | REPEATABLE-READ |
+--------------------------------+---------------------------------+
Then, we set READ-UNCOMMITTED to "transaction_isolation" global variable as shown below:
mysql> SET GLOBAL transaction_isolation = 'READ-UNCOMMITTED';
Then, READ-UNCOMMITTED is only set to "transaction_isolation" global variable as shown below:
mysql> SELECT ##global.transaction_isolation, ##session.transaction_isolation;
+--------------------------------+---------------------------------+
| ##global.transaction_isolation | ##session.transaction_isolation |
+--------------------------------+---------------------------------+
| READ-UNCOMMITTED | REPEATABLE-READ |
+--------------------------------+---------------------------------+
Then, log out MySQL:
mysql> exit
Then, log in MySQL:
C:\Users\kai>mysql -u root -p
Now, READ-UNCOMMITTED is also set to "transaction_isolation" session variable as shown below:
mysql> SELECT ##global.transaction_isolation, ##session.transaction_isolation;
+--------------------------------+---------------------------------+
| ##global.transaction_isolation | ##session.transaction_isolation |
+--------------------------------+---------------------------------+
| READ-UNCOMMITTED | READ-UNCOMMITTED |
+--------------------------------+---------------------------------+
And for example about "wait_timeout", 28800 is the default value for "wait_timeout" global and session variables as shown below:
mysql> SELECT ##global.wait_timeout, ##session.wait_timeout;
+-----------------------+------------------------+
| ##global.wait_timeout | ##session.wait_timeout |
+-----------------------+------------------------+
| 28800 | 28800 |
+-----------------------+------------------------+
Then, we set 1000 to "wait_timeout" global variable as shown below:
mysql> SET GLOBAL wait_timeout = 1000;
Then, 1000 is only set to "wait_timeout" global variable as shown below:
mysql> SELECT ##global.wait_timeout , ##session.wait_timeout;
+-----------------------+------------------------+
| ##global.wait_timeout | ##session.wait_timeout |
+-----------------------+------------------------+
| 1000 | 28800 |
+-----------------------+------------------------+
Then, log out MySQL:
mysql> exit
Then, log in MySQL:
C:\Users\kai>mysql -u root -p
Now, 1000 is not set to "wait_timeout " session variable as shown below:
mysql> SELECT ##global.wait_timeout , ##session.wait_timeout;
+-----------------------+------------------------+
| ##global.wait_timeout | ##session.wait_timeout |
+-----------------------+------------------------+
| 1000 | 28800 |
+-----------------------+------------------------+
So in this case, just set 1000 to "wait_timeout " session variable as shown below;
mysql> SET SESSION wait_timeout = 1000;
Or, set DEFAULT which is 1000 of "wait_timeout" global variable to "wait_timeout" session variable as shown below:
mysql> SET SESSION wait_timeout = DEFAULT;
Now, 1000 is also set to "wait_timeout" session variable as shown below:
mysql> SELECT ##global.wait_timeout, ##session.wait_timeout;
+-----------------------+------------------------+
| ##global.wait_timeout | ##session.wait_timeout |
+-----------------------+------------------------+
| 1000 | 1000 |
+-----------------------+------------------------+
Related
My team is getting this below error message on AWS Cluster Aurora RDS on reader and writer instances:
Waiting for table level lock
Kindly note:
We are NOT USING Lock Tables explicitly anywhere
We are NOT USING MyISAM Tables
We are NOT USING any Kind of MYSQL Dump
.
mysql> show variables like '%innodb_table%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| innodb_table_locks | ON |
+--------------------+-------+
1 row in set (0.00 sec)
mysql> show variables like '%innodb_autoinc_lock_mode%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| innodb_autoinc_lock_mode | 1 |
+--------------------------+-------+
1 row in set (0.00 sec)
For those who know about this issue - Is there anyway we can replicate the issue on our Testing Node.
Is it normal, that the MySQL global variable gtid_executed changes multiple times in a minute?
These MySQL commands were executed in a time range of 10 seconds:
mysql> show global variables like 'gtid_executed';
+---------------+-------------------------------------------------+
| Variable_name | Value |
+---------------+-------------------------------------------------+
| gtid_executed | d4eeed2f-6cc7-11e9-aa15-fa163e5318c7:1-26918205 |
+---------------+-------------------------------------------------+
1 row in set (0.00 sec)
mysql> show global variables like 'gtid_executed';
+---------------+-------------------------------------------------+
| Variable_name | Value |
+---------------+-------------------------------------------------+
| gtid_executed | d4eeed2f-6cc7-11e9-aa15-fa163e5318c7:1-26918206 |
+---------------+-------------------------------------------------+
1 row in set (0.00 sec)
mysql> show global variables like 'gtid_executed';
+---------------+-------------------------------------------------+
| Variable_name | Value |
+---------------+-------------------------------------------------+
| gtid_executed | d4eeed2f-6cc7-11e9-aa15-fa163e5318c7:1-26918207 |
+---------------+-------------------------------------------------+
1 row in set (0.00 sec)
Every time there is a different value! Is that normal?
It is a single node SaaS MySQL RDS instance in a cloud environment.
Thank you kindly in advance.
If you have activity on the server this is a normal behaviour, as for each new transaction a new GTID value is assigned to it incremented by one.
I'm using MySQL 5.7.25 and i want to increase my MySQL password policy by doing this in MySQL command:
SET GLOBAL validate_password_policy=2;
But i always get an error:
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
I tried to list the validate_password variable:
SHOW VARIABLES LIKE 'validate_password%'
but it always return empty set
This problem has happened because validate_password plugin is by default NOT activated. You can solve by these commands:
mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate%';
Empty set (0.00 sec)
mysql> install plugin validate_password soname 'validate_password.so';
Query OK, 0 rows affected (0.02 sec)
mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate%';
Finally, you will show the following:
+-------------------+---------------+
| plugin_name | plugin_status |
+-------------------+---------------+
| validate_password | ACTIVE |
+-------------------+---------------+
1 row in set (0.00 sec)
Then you can run your command:
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec).
This command works for me. I'm using MySQL 8.
SET GLOBAL validate_password.policy=LOW;
SET GLOBAL validate_password_policy=LOW;
Replace validate_password(dot)policy with validate_password_policy
In MySQL there are two values for some parameters:
1) For session.
2) For global.
We can check the values for such parameters like:
1) show variables like 'wait_timeout'
2) show global variables like 'wait_timeout'
Now it returns the values:
1) for session = 500
2) For global = 28800
I am able to change the variables by command:
set global wait_timeout=100 ;
set session wait_timeout= 200;
But when i logged in again i am getting the following values:
for session = 500
for global = 100.
It means global values retain and session not, which is absolutely correct.
But my concern is how we can change the session variables then for all sessions ?
Because global is not that values taken by each session in this case.
Yes,
there a 2 timeouts in MySQL. which one is take for your connection depends on the connections type. one is for the BATCH processing and the other for interactive
the second variable is the interactive_timeout.
look at the setting of interactive_timeout
SHOW VARIABLES LIKE 'interactive_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
sample login via mysql client
# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 106426
Server version: 10.1.10-MariaDB-log Homebrew
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 500 |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]> show variables like 'interactive_timeout';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| interactive_timeout | 500 |
+---------------------+-------+
1 row in set (0.01 sec)
MariaDB [(none)]> show global variables like 'interactive_timeout';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| interactive_timeout | 500 |
+---------------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]>
now the same in batch mode
# mysql -uroot -p -e "show variables like 'wait_timeout';"
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
#
I got the exact description:
On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect())
In MySQL doc wait_timeout description
For testing, I almost rebuild the newly designed MySQL database every day recently, I also have a Php application based on that. For my understanding, some of system variables value has been accumulated in every rebuild, such as:
mysql> show global status like '%tmp%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 14062 |
| Created_tmp_files | 437 |
| Created_tmp_tables | 20854 |
+-------------------------+-------+
3 rows in set (0.00 sec)
Created_tmp_disk_tables and Created_tmp_tables are growing constantly based on every rebuild. Surely there are some other variables doing same thing. I wonder how can we clean them safely in every rebuild, so we won't be cheated by these values. We will see the real value.
Please feel free to let me know if the question is not clear. Thanks.
after testing #dwjv's suggestion, doing 'flush status', got:
mysql> flush status;
Query OK, 0 rows affected (0.02 sec)
mysql> show global status like '%tmp%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 14062 |
| Created_tmp_files | 0 |
| Created_tmp_tables | 20856 |
+-------------------------+-------+
3 rows in set (0.00 sec)
The variable 'Created_tmp_files' was cleaned, but other two didn't change.
'Flush status' will only reset the session status, some, but not all the global status variables.
mysql> show status like '%tmp%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 0 |
| Created_tmp_tables | 0 |
+-------------------------+-------+
3 rows in set (0.00 sec)
Then I followd &Yak's suggestion 'service mysql restart', got:
mysql> show global status like '%tmp%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 14062 |
| Created_tmp_files | 0 |
| Created_tmp_tables | 20857 |
+-------------------------+-------+
3 rows in set (0.00 sec)
Still same, no change.
All you need to do is restart the server.
FLUSH STATUS;
This will flush many of the global variables.