mysql can't change a session variable group_concat_max_len - mysql

In MySQL help it says that "Setting a session variable requires no special privilege, but a client can change only its own session variables, not those of any other client."
I try to increase the size of group_concat_max_len like this:
SET ##group_concat_max_len = 9999;
In phpmyadmin, the response is positive: 'Your SQL query has been executed successfully'.
Then I check the value like this (in the same window, 2 seconds later):
SHOW SESSION VARIABLES;
And unfortunately, group_concat_max_len = 1024
I am not the admin of this MySQL server, but if changing session variable does not require special privilege, then it should work. On my localhost it works.
Is there any chance to set this variable or at least to know why it can't be changed?

In phpmyadmin it is not guaranteed, that 2 queries (even if they are separated only by a few seconds) go to the same session. So chances are, SET ##group_concat_max_len = 9999; went to one session, but SHOW SESSION VARIABLES; to another.
If you try from the mysql command line client, this will work as expected.

Related

Change Global database timeout duration in Oracle SQL with query

I want to change my global timeout duration for all database like global timeout.
How can I do that with query in OracleSQL.
Example for MySQL:
SELECT ##LOCK_TIMEOUT
SET LOCK_TIMEOUT 10000;
SELECT ##LOCK_TIMEOUT
I believe this is what you wanted:
By default, the ddl_lock_timeout parameter is set to zero seconds to
wait, making it equivalent to the earlier NOWAIT behavior. But this
can easily be changed to make DDL run in WAIT mode by setting
ddl_lock_timeout to a non-zero value:
alter session set ddl_lock_timeout= 60
Now, DDL will wait 60 seconds before aborting with a ORA-00054 error.

Default global sql_mode setting for server

I have the sql_mode on a shared server set to
ONLY_FULL_GROUP_BY,​STRICT_TRANS_TABLES,​NO_ZERO_IN_DATE,​NO_ZERO_DATE,​ERROR_FOR_DIVISION_BY_ZERO,​NO_AUTO_CREATE_USER,​NO_ENGINE_SUBSTITUTION
What would happen if I removed these variables, and it remains blank? Would it affect other users? Some users want the sql_mode blank, while my thinking is that they should set their own modes using their code.
session_start();
include_once("./includes/conn.php");
mysql_query("SET SESSION sql_mode = ''");
The whole point of asking this question is to solve the problem at the level its occurring rather than altering a global setting

SET a variable in mysql only once

I am using classic ASP and MySQL (using PHP wouldn't change the point of the question).
I need to set a variable over my homepage:
SET block_encryption_mode = 'aes-256-cbc'
I can not set it as global variable as other users are using the server and may use the default block_encryption_mode.
I know I can use the statement using ASP/PHP on the beginning of each webpage, but that seems like using too much resources; every user will execute the SET statement on every page...
Is there a way to SET variable or execute some other SQL statement at the beggining on each session, like an onstart event like ASP has, maybe? Or how could I achieve my goal without executing the query for each user on every page I have?
You can use the init_connect variable.
A string to be executed by the server for each client that connects. The string consists of one or more SQL statements, separated by semicolon characters.
You can also distinguish the users with code like this:
IF (CURRENT_USER() = 'special_crypto_dude#localhost') THEN
SET SESSION block_encryption_mode = 'aes-256-cbc';
END IF;
It is safe to call SET on every page as it executes in orders of microseconds. There is literally no overhead calling SET on already open connection.
Unless you can apply this setting globally, I would not bother. Just set the block_encryption_mode (together with collation and timezone) directly after acquiring the database connection handle.

how to set sql mode variable as a local variable in mysql

What i want thing is, i want to set the sql_mode variable as a local variable, not as a session or global variable. Reason to do that is i want to disapear the change of sql mode variable after one of query was executed. Below session and global are worked well, but this is not the what i want. Global one is kept the sql mode as a empty one forever. Session one is kept the sql mode as a empty one until connection close. I want thing is, keep the sql mode until a quarry is executed only.
mysql> set global sql_mode='';
mysql> set session sql_mode='';
mysql query :-
SELECT tc_exe_grp_num,tcs.tc_tc_id,tcs.tcs_id
FROM tc_exe_res tcer
INNER JOIN tcs tcs
ON tcs.tcs_id = tcer.tcs_tcs_id
WHERE tcs.tc_tc_id='1'
AND tcs.tc_tc_id='1'
GROUP BY tc_exe_grp_num
ORDER BY tc_exe_grp_num ;
got the idea from this article
please help me.
##sql_mode is session variable, not a local variable.
It is possible to retrieve the current setting of sql_mode, and save it in a user-defined variable, and then later set sql_mode back to the original setting.
For example:
-- save current setting of sql_mode in user defined variable
-- change sql_mode to desired setting
SET #SAVE_sql_mode = ##sql_mode ;
SET ##sql_mode = 'NO_ENGINE_SUBSTITUTION' ;
-- subsequent operations run under new setting of sql_mode
SELECT '...';
-- set sql_mode back to saved setting
SET ##sql_mode = #SAVE_sql_mode ;
I couldn't find a direct answer for this, but there is a solution,
First set the "sql mode" as a empty one and after quarry was executed set the "sql mode" with what previously had values, try it in below way,
set session sql_mode='';
SELECT tc_exe_grp_num,tcs.tc_tc_id,tcs.tcs_id FROM tc_exe_res tcer INNER JOIN tcs tcs ON tcs.tcs_id = tcer.tcs_tcs_id WHERE tcs.tc_tc_id='1' AND tcs.tc_tc_id='1' group by tc_exe_grp_num ORDER BY tc_exe_grp_num ;
set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Cannot set a global variable on MySQL

I'm using MySQL in localhost (in ubuntu and also in windows). I want to set a global variable, and I have tried in all ways but even though I get an "ok" message from mysql, then when I do the "select #var" it allways says "NULL".
I've tried:
set global var=17;
set #global.var=17;
set ##var=17;
Can anyone help me?
Thanks in advance.
ps: I have the SUPER privilege.
The variable name var does not reference a valid system variable. The GLOBAL and SESSION keywords in the SET statement are used for specifying the scope when setting MySQL system variables, not MySQL user variables.
Try for example:
SELECT ##global.net_read_timeout ;
SET GLOBAL net_read_timeout = 45 ;
SELECT ##global.net_read_timeout ;
http://dev.mysql.com/doc/refman/8.0/en/set-statement.html
http://dev.mysql.com/doc/refman/5.5/en/set-statement.html
According to the MySQL 5.0 Reference Manual:
User-defined variables are session-specific. That is, a user variable
defined by one client cannot be seen or used by other clients. All
variables for a given client session are automatically freed when that
client exits.
You could consider using an extension like MySQL Global User Variables UDF (old archived link) to use global (persistent shared) variables.
On MySQL, you cannot create custom global or session system variables but can change existed global or session system variables as shown below:
SET GLOBAL max_connections = 1000; -- Existed global system variable
SET SESSION sql_mode = 'TRADITIONAL'; -- Existed session system variable
And, you can create user-defined(custom) variables which are removed when you exit(log out) a session as shown below. User-defined variables exist only in the current session so they cannot be seen by other sessions unless you use performance_schema.user_variables_by_thread:
SET #first_name = 'John', #last_name = 'Smith';