Mysql Mode On Linux CentOS - mysql

I installed Mysql 5.6 On CentOS Linux
By Default it Set SQl Mode Strict
SELECT ##GLOBAL.sql_mode;
+--------------------------------------------+
| ##GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
SELECT ##SESSION.sql_mode;
+--------------------------------------------+
| ##SESSION.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
I changed sql_mode via command line from root User to none via command
SET SESSION sql_mode = '';
SET GLOBAL sql_mode = '';
After this i executed commands above commands and they showed
SELECT ##SESSION.sql_mode;
+--------------------+
| ##SESSION.sql_mode |
+--------------------+
| |
+--------------------+
1 row in set (0.00 sec)
mysql> SELECT ##GLOBAL.sql_mode;
+-------------------+
| ##GLOBAL.sql_mode |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
But when i restarted Mysql Server i again set Strict Mode i.e
SELECT ##GLOBAL.sql_mode;
+--------------------------------------------+
| ##GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
SELECT ##SESSION.sql_mode;
+--------------------------------------------+
| ##SESSION.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
I also added mysql-mode="" in my.cnf file but result was same after restarting mysql

Add in your my.cnf file :
sql_mode = ""
Then restart mysql
Here is what it should look like :
user = nobody
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock
skip-external-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
open_files_limit = 50k
sql_mode = ""

I had the same problem & here is what I worked:
edit /etc/mysql/my.cnf
and add the following
[mysqld]
sql-mode=""
you can also check out the documentation: https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html

Please note that in Centos, you need to follow these steps:
Login to root
Clieck on SQL services then select MySQL Configuration
It will open the configuration file
At the end of that file add below:
sql_mode="" (not sql-mode="")
Go back to Dashboard and try to restart MySQL Database Server available at the right bottom side.
If there is any error in config file, it will throw an error, go back and fix the error accordingly.
If you want to test this in command mode use this like:
service mysqld restart
and make sure that it is showing OK in green letters.

Related

Time zone in Linux and in MySQL 8.0

I am trying to set the time zone in MySQL so that it matches the Ubuntu 20.04 time zone. When I check the error.log for MySQL I see a different set of data for the time zone.
Here is what I have from the system, MySQL 8.0.23 and the error.log:
sudo nano /etc/mysql/my.cnf
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
default-time-zone = "SYSTEM"
Console commands:
date
Sat 01 Jan 2022 10:01:29 PM EST
var/log/mysql/error.log
2022-01-02T02:31:15.751387Z 0 [System] [MY-010931] [Server]
mysql
mysql> SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2022-01-01 22:04:43 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT ##global.time_zone;
+--------------------+
| ##global.time_zone |
+--------------------+
| SYSTEM |
+--------------------+
1 row in set (0.00 sec)
After further research I found what I was looking for in the post at stackoverflow.com/questions/35123049/… this change did the trick:
[mysqld]
log_timestamps = SYSTEM

MySQL applys global variables to opened session

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 |
+-----------------------+------------------------+

MySQL wait_timeout global and session setting issue

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

mysql-multi: how to select instance by port (instead of socket)?

I have a second mysql instance running with mysqld_multi on port 3307. If connecting to it by port i get the databases from the first instance, like connecting to 3306. If i connect by socket i get the correct databases from the second instance. I need this second instance for a test environment, so i need to select the instance and it's storage/datadir by port. Can you help me?
my.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = something
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld2]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
socket = /var/lib/mysql2/tmp/mysql2.sock
port = 3307
pid-file = /var/run/mysqld/mysqld2.pid
datadir = /var/lib/mysql2
language = /usr/share/mysql/english
user = mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
systemctl status mysqld
mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Mo 2016-02-08 12:54:40 CET; 24h ago
Process: 6901 ExecStartPost=/usr/bin/mysql-systemd-start post code=exited, status=0/SUCCESS)
Process: 6889 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6900 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─6900 /bin/sh /usr/bin/mysqld_safe
└─7062 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
mysqld_multi report
WARNING: Log file disabled. Maybe directory or file isn't writable?
mysqld_multi log file version 2.16; run: Di Feb 9 13:54:19 2016
Reporting MySQL servers
MySQL server from group: mysqld2 is running
Connect to first instance
$ mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
Connect to second instance by port
$ mysql -P 3307 -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
Connect to second instance by socket
$ mysql -S /var/lib/mysql2/tmp/mysql2.sock -u root -p
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3307 |
+---------------+-------+
1 row in set (0,00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tmp |
+--------------------+
4 rows in set (0,00 sec)
Server
CentOS 7 with MySQL 5.6.25

why mysql server character cannot be set as the setting(utf8) in my-default.ini(windows)?

Here is my-default.ini
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required
default-character-set = utf8
character_set_server = utf8
basedir = D:\Program Files\mysql
datadir = D:\Program Files\mysql\data
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
But in command line
mysql> show variables like 'character%';
+--------------------------+----------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\mysql\share\charsets\ |
+--------------------------+----------------------------------------+
8 rows in set
mysql>
as you see,I really do lots of settings in the my-defualt.ini,but every time MYSQL server start , character_set_server is always latin1.
I want it to be utf8,how can I make it?
I want to why?
Thanks!!!
Probably you need to copy my-default.ini to my.ini, since the latter is what mysqld looks for by default.
Otherwise, I can't duplicate your problem.
I'm running 5.6.12 on Windows 8.1. Here is the test case, starting with no mention of character_set_server in my.ini:
mysql> show variables like 'char%';
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 | -- Note
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)
mysql> create database whatischarset;
Query OK, 1 row affected (0.03 sec)
mysql> show create database whatischarset;
+---------------+--------------------------------------------------------------------------+
| Database | Create Database |
+---------------+--------------------------------------------------------------------------+
| whatischarset | CREATE DATABASE `whatischarset` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+---------------+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
At this point, I added character_set_server = utf8 to the [mysqld] section of the appropriate my.ini; then restarted mysqld. Now...
mysql> show variables like 'char%';
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 | -- Note
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)
mysql> create database whatischarset2;
Query OK, 1 row affected (0.00 sec)
mysql> show create database whatischarset2;
+----------------+-------------------------------------------------------------------------+
| Database | Create Database |
+----------------+-------------------------------------------------------------------------+
| whatischarset2 | CREATE DATABASE `whatischarset2` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------------+-------------------------------------------------------------------------+
1 row in set (0.00 sec)
How does this compare to what you did?