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
Related
I want to change timezone in mysql from EDT to GMT ,
SELECT ##system_time_zone;
+--------------------+
| ##system_time_zone |
+--------------------+
| EDT |
+--------------------+
1 row in set (0.00 sec)
on researching google I am hitting its not possible ! I am pretty sure it should be.
For the current session, just:
SET ##session.time_zone='+00:00'; -- UTC
Or:
SET time_zone = '+00:00';
To make it permanent, you can change mysqld conf file (requires a server restart):
default_time_zone='+00:00'
Demo on DB Fiddle:
SELECT ##global.time_zone, ##session.time_zone;
##global.time_zone | ##session.time_zone
:----------------- | :------------------
SYSTEM | SYSTEM
SET ##session.time_zone='+00:00';
SELECT ##global.time_zone, ##session.time_zone;
##global.time_zone | ##session.time_zone
:----------------- | :------------------
SYSTEM | +00:00
I'm trying to use grafana with mysql. MySql is getting data from wordpres. I can connect to the MySql database with grafana but any attempt to query the database results in a permission error quoted below. Does anyone know what I'm doing wrong? I made sure to FLUSH PRIVILEGES; when creating this account.
What account is being used?
mysql> SELECT USER(),CURRENT_USER();
+-------------------+-------------------+
| USER() | CURRENT_USER() |
+-------------------+-------------------+
| grafana#localhost | grafana#localhost |
+-------------------+-------------------+
1 row in set (0.00 sec)
What permissions does the account have?
mysql> show grants for 'grafana'#'localhost';
+------------------------------------------------------------------------+
| Grants for grafana#localhost |
+------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'grafana'#'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)
Can I select from a table? (Yes)
mysql> select * from wp_users;
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
| 1 | admin | ********************************** | admin | a.guy#place.com | | 2019-02-22 18:09:58 | | 0 | something |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
1 row in set (0.00 sec)
What is my mysql info?
mysql> status
--------------
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Connection id: 42787
Current database: information_schema
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 43 days 2 hours 29 min 53 sec
Threads: 3 Questions: 3576291 Slow queries: 0 Opens: 1570 Flush tables: 1 Open tables: 692 Queries per second avg: 0.960
--------------
What query am a trying to run in grafana?
SELECT
user_registered,
user_login
FROM wp_users
I tried with with and without a trailing ; - no change.
What does grafana give back to me with this query?
Error 1142: SELECT command denied to user 'grafana'#'localhost' for table 'wp_users'
I realize that this account has too many permissions, but seeing as grafana thinks it doesn't have enough, for now I'm trying to get it to work with at least more than it needs.
After being stumped by this for a few hours, the notion of looking at logs was suggested to me. Since MySql doesn't have logs enabled by default, I changed the settings to enable the logs and restarted MySql. After doing this everything worked fine. It seems all I had to do was to restart the service.
The solution:
sudo service mysql restart
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
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.
In my server, I have the following from the command line:
]$ date
Fri Sep 16 13:47:02 JST 2011
Which is correct.
in mysql, I have the following:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-09-16 04:50:21 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
1 row in set (0.00 sec)
So, it is set to the system time, but then why is not showing the same time?
You just need to restart mysqld after altering timezone of System..
The Global time zone of MySQL takes timezone of System. When you change any such attribute of system, you just need a restart of Mysqld.
That's it.
Your queries are returning the values in UTC but from the command line output your system is in JST. Since the variables are returning SYSTEM I would suggest that perhaps your configuration has identified system as UTC. Check out your my.cnf as suggested here How do I make MySQL's NOW() and CURDATE() functions use UTC?.