Mysql function change to default value automatically after restart mysql server - mysql

If I restart the mysql server, it changes the value to default value automatically.
mysql> show global variables like 'log_bin_trust_function_creators';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL log_bin_trust_function_creators = ON;
Query OK, 0 rows affected (0.00 sec)
I would like to make this function ON no matter what happen.
Is there way to make it the my value to default value?

Specify the log-bin-trust-function-creators option in an option file (or use the --log-bin-trust-function-creators argument to mysqld on the command-line if you prefer).

Related

How can I enable strict sql_mode in MySQL?

How can I enable strict sql_mode in MySQL?
I want to fetch data from SQL and process the same in strict mode.
My current sql_mode is:
mysql> SELECT ##sql_mode;
+------------------------+
| ##sql_mode |
+------------------------+
| NO_ENGINE_SUBSTITUTION |
+------------------------+
You basically have two ways of doing it, using SQL command or changing configuration file. If you set it using SQL command - it will change back after the server is restarted.
Doing it in SQL:
SET GLOBAL sql_mode='STRICT_TRANS_TABLES';
Doing it in config file:
[mysqld]
sql_mode="STRICT_TRANS_TABLES"
File location varies depending on your operating system, more on where to find it here: https://dev.mysql.com/doc/refman/5.7/en/option-files.html
Important to note, that you can have multiple modes specified:
sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
this is especially important when using SQL statement, since it could override your whole mode string.
More stuff about SQL modes here: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
Do the following:
SET GLOBAL sql_mode='STRICT_TRANS_TABLES';
The other answers are correct, but they don't work (as-is) for AWS RDS.
If you are running a MySQL server on AWS RDS, then you can't run SET GLOBAL sql_mode='STRICT_TRANS_TABLES'; straightaway because you don't have the requisite permissions, even with admin-level credentials:
mysql> SET GLOBAL sql_mode='STRICT_ALL_TABLES';
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
In AWS RDS, since it's a managed DB service, you don't have access to the my.cnf or other configuration files directly - so you can't change the settings there either.
However, note that you can set sql_mode at the session-level, but this will be lost across session changes or reboots:
mysql> SET SESSION sql_mode='STRICT_ALL_TABLES';
Query OK, 0 rows affected, 1 warning (0.30 sec)
mysql> SELECT ##session.sql_mode;
+---------------------+
| ##session.sql_mode |
+---------------------+
| STRICT_ALL_TABLES |
+---------------------+
1 row in set (0.31 sec)
So then how do you change sql_mode (or any other parameters for that matter) at a GLOBAL level so that they persist across restarts in AWS RDS MySQL?
You need to create a custom DB Parameter Group in RDS (for example, using the web console) like this:
Then you have to modify your RDS instance and apply the newly-created Parameter Group like so:
Finally, apply your modifications, and reboot (yes, reboot is required) the instance.
And voila, you have your sql_mode set as needed, and it persists across reboots now:
mysql> SELECT ##sql_mode;
+------------------------------------------+
| ##sql_mode |
+------------------------------------------+
| STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION |
+------------------------------------------+
1 row in set (0.69 sec)
mysql> SELECT ##global.sql_mode;
+------------------------------------------+
| ##global.sql_mode |
+------------------------------------------+
| STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION |
+------------------------------------------+
1 row in set (0.62 sec)
mysql> SELECT ##session.sql_mode;
+------------------------------------------+
| ##session.sql_mode |
+------------------------------------------+
| STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION |
+------------------------------------------+
1 row in set (0.38 sec)

set mysql session and global sql_mode when service start

I am using mysql Server version: 5.5.37 and in current mysql whenever i will restart mysql service that time i saw below results
mysql> select ##GLOBAL.sql_mode;
+--------------------------------------------+
| ##GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select ##session.sql_mode;
+--------------------------------------------+
| ##session.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
But i want to set mysql mode for both(session as well as global) whenever service is restart.i have also tried to put below line in /etc/my.cnf file
but its not working fine
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
so is it possible to set from any core file or else where ?
please shine on this topic
i need help to set up session and global both sql_mode to 'NO_ENGINE_SUBSTITUTION'
This is how I set SQL mode in my /etc/my.conf file:
[mysqld]
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Make sure your MySQL daemon has permissions to read this file. Also, check if there are any other my.conf files that may override your value. MySQL searches and reads config files in multiple locations. Read more here http://dev.mysql.com/doc/refman/5.7/en/option-files.html

How to increase MySQL connections(max_connections)?

Every socket of MySQL Database will have defaults connections as 100 but I am looking for any way to increase the number of possible connections > 100 to a socket connection of MySQL Database.
If you need to increase MySQL Connections without MySQL restart do like below
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL max_connections = 150;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 150 |
+-----------------+-------+
1 row in set (0.00 sec)
These settings will change at MySQL Restart.
For permanent changes add below line in my.cnf and restart MySQL
max_connections = 150
From Increase MySQL connection limit:-
MySQL’s default configuration sets the maximum simultaneous connections to 100. If you need to increase it, you can do it fairly easily:
For MySQL 3.x:
# vi /etc/my.cnf
set-variable = max_connections = 250
For MySQL 4.x and 5.x:
# vi /etc/my.cnf
max_connections = 250
Restart MySQL once you’ve made the changes and verify with:
echo "show variables like 'max_connections';" | mysql
EDIT:-(From comments)
The maximum concurrent connection can be maximum range: 4,294,967,295. Check MYSQL docs
I had the same issue and I resolved it with MySQL workbench, as shown in the attached screenshot:
in the navigator (on the left side), under the section "management", click on "Status and System variables",
then choose "system variables" (tab at the top),
then search for "connection" in the search field,
and 5. you will see two fields that need to be adjusted to fit your needs (max_connections and mysqlx_max_connections).
Hope that helps!
The system does not allow me to upload pictures, instead please click on this link and you can see my screenshot...

MySQL Slow Log issues - long_query_time does not go into effect

I have followed a few tutorials in tracking down slow queries through the slow query log.
I have tried changing long_query_time to the value of 1 for testing purposes, but whatever I do, a query only makes it into the log when the default time of 10 is reached.
I tried:
set ##GLOBAL.long_query_time = 1;
set global long_query_time = 1;
When using either of these commands:
show variables like '%long%';
show global variables like '%long%';
I get the result that the variable was changed.
I have the exact same query running, just adding more LEFT JOIN entries to make it run longer. Whenever the query runs 10 seconds or longer, it is logged, but it does NOT show up in the log when it runs less than that, even though all my variables appear to say they are changed.
I am logged into MySQL as root as I make these changes.
I restarted Apache and MySQL, still no dice.
My version information is:
Server version: 5.1.63-log SUSE MySQL RPM
When I query both the session and the global variables (I tried both), I get this:
mysql> show variables like '%long%';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| long_query_time | 1.000000 |
| max_long_data_size | 1048576 |
+--------------------+----------+
2 rows in set (0.00 sec)
mysql> show global variables like '%long%';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| long_query_time | 1.000000 |
| max_long_data_size | 1048576 |
+--------------------+----------+
2 rows in set (0.00 sec)
The general logging feature is obviously on, and it is redirected to TABLE or I wouldn't get an entry in the log at all.
The setting log_queries_not_using_indexes if turned on starts logging EVERY query even if it does not take 1 second to execute.
What am I missing?
Thanks!
The configuration below turns MySQL to log queries which execution time is more than half second:
slow_query_log = 1
long_query_time = 0.5
log-slow-queries = /var/log/mysql/log-slow-queries.log
log_queries_not_using_indexes = 0

Should OPTIONAL User Settings be Lazy-Initialized into the DB or always created with a new registration?

Simple question: Should OPTIONAL User Settings be Lazy-Initialized into the DB or always created with a new registration?
A user can set additional settings which are optional, so should a row for that optional setting be created for every user upon registration or only created when a user makes use of those settings for the first time?
Lazy-Initialization saves space, so I'm leaning towards doing it this way, but I'm not sure if there are any drawbacks.
Do the lazy initialization. Here's why.. if you instead used default values for settings the user didn't actively choose, and then later the business rules changed to set the default to something else, you'd have users with what would appear to be non-default settings that they didn't actively choose.
Here is one particular drawback I ran into when using lazy initilization in MySQL. It all boils down to this quote from the MySQL docs:
User-defined variables are connection-specific.
First: The setup
Connect to your DB (in my case MySQL) Then create a simple function SetBarProperty() that sets the #bar property EXPLICITLY to the value passed to the function. The function itself simply returns the value passed to it.
$ mysql
mysql> DROP FUNCTION IF EXISTS SetBarProperty;
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER $$
mysql> CREATE FUNCTION SetBarProperty( myValue INT(30) )
-> RETURNS INT(30)
-> DETERMINISTIC
-> READS SQL DATA
-> BEGIN
-> SET #bar := myValue;
-> RETURN myValue;
-> END $$
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;
Now if we query for the #bar property, it will be NULL just as expected.
mysql> SELECT #bar;
+------+
| #bar |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
Again, if we call the SetBarProperty(3); the result is just as expected.
mysql> SELECT SetBarProperty(3);
+-------------------+
| SetBarProperty(3) |
+-------------------+
| 3 |
+-------------------+
1 row in set (0.00 sec)
What do you think?
What do you think happens if we call the following query?
SELECT SetBarProperty(4), #bar;
You've guessed right! #bar is 4.
mysql> SELECT SetBarProperty(4), #bar;
+-------------------+------+
| SetBarProperty(4) | #bar |
+-------------------+------+
| 4 | 4 |
+-------------------+------+
1 row in set (0.00 sec)
And now the tricky part...
Disconnect from your DB server (this is very important):
Ctrl+C
Now re-connect and call the same query as before:
$ mysql
mysql> SELECT SetBarProperty(4), #bar;
+-------------------+------+
| SetBarProperty(4) | #bar |
+-------------------+------+
| 4 | NULL |
+-------------------+------+
1 row in set (0.00 sec)
Did you see what just has happened?
#bar was NULL and this is because it hasn't been initialized in the caller space of the function SetBarProperty().
If you disconnect from your DB and explicitly initialize the property BEFORE calling the function (that itself initializes it explicity) your query works just as expected:
Ctrl+C
$ mysql
mysql> SET #bar := NULL;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT SetBarProperty(4), #bar;
+-------------------+------+
| SetBarProperty(4) | #bar |
+-------------------+------+
| 4 | 4 |
+-------------------+------+
1 row in set (0.00 sec)
Recommendation
If you immediately use a property in a query just after you've called a function that modifies the same property you should initialize the property before calling the function.
I hope this helps!
Regards,
Konrad