I am using this time-zone-support for setting the UTC timezone on my machine,
But the trouble is that I am not able to set it permanently, it changes to System time when I restart the MySQL server.
The box is OpenSuse 12.3, and the MySQL version is 5.5.33
mysql> SET time_zone = UTC;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| UTC | UTC |
+--------------------+---------------------+
1 row in set (0.00 sec)
now when I restart the mysql server, it reverts back to system.
After restarting the server:
mysql> SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
1 row in set (0.00 sec)
I have tried doing the default time zone as well, but its giving me error.
mysql> default-time-zone=UTC;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default-time-zone=UTC' at line 1
mysql>
Can someone please let me know what am I missing here, and how to set the UTC timezone permanently.
I am answering my own question, as in the pursuit of the answer I have found the solution here
I was editing my.cnf file and entering default-time-zone = UTC at the end of the file, as I did in windows machine, it does NOT work in Linux/Opensuse.
Then I entered default-time-zone = UTC in the [mysqld] section of the my.cnf, and the new time zone is picked up, and now the UTC timezone is set permanently.
Related
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)
I have the following SQL:
FROM_UNIXTIME(1392354000)
When I insert that into the database in my insert statement, the value that gets saved is:
2014-02-13 19:00:00
However, this is not correct, because it should be like this:
2014-02-14 00:00:00
If you copy and paste the timestamp at http://www.unixtimestamp.com/index.php it will show the 14th of Feb.
What can I do to make my timestamp be the 14th of Feb (not the 13th)? Preferably, it would be as shown above (2014-02-14 00:00:00).
This is happening because the timezone of your mysql is not same as the URL you are testing with.
In the URL the timezone is UTC.
So to test this you can try this
First check the timezone set for your mysql server with the following command
SELECT ##global.time_zone;
This will show you the timezone result, and if its set to UTC you will get something as
+--------------------+
| ##global.time_zone |
+--------------------+
| +00:00 |
+--------------------+
else you will get some other result.
Now if its something else which is more likely as you mentioned
Try this
SET ##global.time_zone='+00:00';
Now your mysql server is having UTC timezone and then run the command
mysql> select FROM_UNIXTIME(1392354000) ;
+---------------------------+
| FROM_UNIXTIME(1392354000) |
+---------------------------+
| 2014-02-14 10:30:00 |
+---------------------------+
Here are few ways to change the timezone of your mysql server
http://www.inmotionhosting.com/support/website/databases/how-to-change-mysql-server-time-zone
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
I've been passing through this problem for one day, and it's hard to understand why MySql doesn't work easily.
I'm trying to execute the statement below, but it isn't recognized at all.
SELECT TO_SECONDS('2013-09-12 11:15:00');
I get the following error:
ERROR 1305 (42000): FUNCTION db.to_seconds does not exist
I've checked MySQL's documentation and this function is available since version 5.5. So, I updated my previous version and now I'm working with 6.0 (Server version: 6.0.4-alpha-community-log MySQL Community Server (GPL)) but still not working.
mysql> select version();
+---------------------------+
| version() |
+---------------------------+
| 6.0.4-alpha-community-log |
+---------------------------+
1 row in set (0.03 sec)
Anyone knows what is going on?
TO_SECONDS('2013-09-12 11:15:00');
Seconds are a measure of time interval not a time datum - this therefore implies some sort of reference datum - but when there's lots to choose from, which do you want? One solution is to define your own datum:
SELECT TIME_DIFF('2013-09-12 11:15:00', '01-01-2000 00:00:00')
Or use the Unix epoch:
SELECT UNIX_TIMESTAMP('2013-09-12 11:15:00')
I was using MySQL version 6.0 that was installed by AppServ (Apache, MySQL, PHP, phpmyadmin) tool and this version of MySQL hasn't support for TO_SECONDS function. After installing MySQL 5.5 it's working perfectly.
mysql> select to_seconds('2013-09-02 13:33:59');
+-----------------------------------+
| to_seconds('2013-09-02 13:33:59') |
+-----------------------------------+
| 63545348039 |
+-----------------------------------+
1 row in set (0.00 sec)
since 2 weeks I puzzled over timezone issue, everything working fine on my localhost BUT it returns wrong value on dedicated server. Let me tell what i have done so far.
First set global timezone by below query: ( Super privilege both on localhost and server )
SET GLOBAL time_zone = '+00:00';
now run below query to cross check whatever done
SELECT NOW(),##global.time_zone AS gtz,##session.time_zone AS stz,
TIMEDIFF(NOW(), CONVERT_TZ( NOW() , ##session.time_zone , '+00:00' ) )
AS OFFSET;
but it display different results on local and dedicated server
on localhost (192.168.x.x) mysql version : 5.5.8
+---------------------+--------+--------+----------+
| NOW() | gtz | stz | OFFSET |
+---------------------+--------+--------+----------+
| 2012-07-02 07:06:55 | +00:00 | +00:00 | 00:00:00 |
+---------------------+--------+--------+----------+
1 row in set (0.00 sec)
on dedicated server (182.168.x.x) mysql version :5.1.53-log
+---------------------+--------+--------+----------+
| NOW() | gtz | stz | OFFSET |
+---------------------+--------+--------+----------+
| 2012-07-02 12:37:59 | +00:00 | +00:00 | 00:00:00 |
+---------------------+--------+--------+----------+
My question is
why NOW() gives wrong time ( above is IST ) whereas
timezone is set to +00:00 ?
side note :
I run below query
SHOW VARIABLES LIKE '%time%zone%';
on localhost
+------------------+---------------------+
| Variable_name | Value |
+------------------+---------------------+
| system_time_zone | India Standard Time |
| time_zone | +00:00 |
+------------------+---------------------+
on server
+------------------+---------------------+
| Variable_name | Value |
+------------------+---------------------+
| system_time_zone | GMT+5 |
| time_zone | +00:00 |
+------------------+---------------------+
does this will affect the result? OR
is there any bug in earlier version of mysql ?
please help me.
When calling NOW() (and related functions), MySQL converts the computer's system clock to the session timezone:
If the system clock is set to 12:30+05:30 and the session timezone is +00:00, the result will be 07:00.
If the system clock is set to 17:30+05:00 and the session timezone is +00:00, the result will be 12:30.
However, one can 'fool' MySQL into thinking that the system clock is in a different timezone to that which the operating system believes by using the --timezone command line argument to mysqld_safe:
If the system clock is set to 17:30+10:30 and the session timezone is +00:00, but MySQL was started in such a way specifying that the system clock should be understood to be GMT+5, the result will be the same as the second bullet above.
You should therefore check:
That the timezone of the system clock reconciles with the value given in the system_time_zone system variable (if it doesn't, ensure that you are not specifying a --timezone argument to mysqld_safe and that there was no TZ environment variable set when mysqld_safe was invoked);
That the system clock is reporting the correct time in its specified timezone.
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.
1) Change your system time and timezone, if necessary.
2) Open mysql console and put in your timezone, smth like this: SET GLOBAL time_zone = "+04:00";
3) Restart mysql.
i have tested-
SET time_zone='+05:30'; it is working,but i dont have global permission so you try by setting server time +05:30 ->
SET GLOBAL time_zone = '+05:30';