Jump to content

  •  

Photo

how to sync time of my server to my database on logging?


  • Please log in to reply
4 replies to this topic

#1 Zirius

Zirius

    Advanced Member

  • Members
  • PipPipPip
  • 262 posts

Posted 17 January 2015 - 07:42 PM

Hello! I have a host which is using a shared SQL (it works great, saves resources), the problem is, the SQL is installed on a server with a different timezone with my VPS. Now, all my logs time are recorded with different time, it is pretty hard for me to use the logs with this...

 

Any workaround?

 

Thanks in advance!


qjMg84B.png


#2 Rand

Rand

    Member

  • Members
  • PipPip
  • 13 posts
  • Github:Rand

Posted 17 January 2015 - 08:37 PM

double sorry


Edited by Rand, 17 January 2015 - 08:40 PM.

 Click rep_up.png if you love your life:)

 


#3 Rand

Rand

    Member

  • Members
  • PipPip
  • 13 posts
  • Github:Rand

Posted 17 January 2015 - 08:38 PM

Hello! I have a host which is using a shared SQL (it works great, saves resources), the problem is, the SQL is installed on a server with a different timezone with my VPS. Now, all my logs time are recorded with different time, it is pretty hard for me to use the logs with this...

 

Any workaround?

 

Thanks in advance!

try:

MySQL: SET time_zone='-03:00';"-03:00" - timezone u need. 

 

if no what os at your vps?


Edited by Rand, 17 January 2015 - 08:40 PM.

 Click rep_up.png if you love your life:)

 


#4 Zirius

Zirius

    Advanced Member

  • Members
  • PipPipPip
  • 262 posts

Posted 17 January 2015 - 08:57 PM

Hello! I have a host which is using a shared SQL (it works great, saves resources), the problem is, the SQL is installed on a server with a different timezone with my VPS. Now, all my logs time are recorded with different time, it is pretty hard for me to use the logs with this...

 

Any workaround?

 

Thanks in advance!

try:

MySQL: SET time_zone='-03:00';"-03:00" - timezone u need. 

 

if no what os at your vps?

 

Oh, so that's how it should works?
I'll try this tomorrow on my server's maintenance.

Should I only query this on LOG database or also on main sql tables?

Thanks!


qjMg84B.png


#5 Rand

Rand

    Member

  • Members
  • PipPip
  • 13 posts
  • Github:Rand

Posted 17 January 2015 - 11:22 PM

no matter but if restart mysql this setting resets. 

 

[color=rgb(0,0,205);]Variant 2.[/color]

  U have full access to mysql server and u can enter SSH as a root user:

 

 

[color=#000000]run below command:[/color]

#mysql or mysql -u root -p 

than enter the password

 

[color=rgb(51,51,51);font-family:'Droid Sans', Arial, Verdana, sans-serif;font-size:13px;]1) Check time_zone* tables in mysql database.[/color]

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql 

[color=rgb(51,51,51);font-family:'Droid Sans', Arial, Verdana, sans-serif;font-size:13px;]2) To change / update timezone [/color]

set global time_zone = timezone; Example: set global time_zone = "Asia/Calcutta";

restart mysql.

 

[color=rgb(51,51,51);font-family:'Droid Sans', Arial, Verdana, sans-serif;font-size:13px;]You can change the time zone as per the requirement without root user.[/color]

set time_zone = timezone; 

[color=rgb(51,51,51);font-family:'Droid Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;]You can see the full list of possible values for ZONEINFO at /usr/share/zoneinfo [/color][color=#ff0000][font="'Droid Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;"]or[/color][/font]

 

VPS. F[color=rgb(0,0,0);font-family:verdana, sans-serif, arial, helvetica;font-size:12px;]rom an SSH:[/color]

ls /usr/share/zoneinfo/ 

[color=rgb(0,0,0);font-family:arial, geneva, sans-serif;]Then simply delete the current timezone:[/color]

rm /etc/localtime

[color=rgb(0,0,0);font-family:arial, geneva, sans-serif;]And replace it with a symbolic link to the new timezone from /usr/share/zoneinfo. For example if your chosen zone is Pacific time:[/color]

ln –s /usr/share/zoneinfo/PST8PDT /etc/localtime

[color=#0000cd][font="'Droid Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;"]Or you can use the tzselect command:[/color][/font]

 

[color=#000000][font="'Droid Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;"]You may need to remove the existing symlink before using tzselect[/color][/font]

rm -f /etc/localtime

than use 

tzselect 

You can make this change permanent for yourself by appending the line

 

TZ='timezone'; 

export TZ to the file '.profile' in your home directory; then log out and log in again.

 

Synchronizing time with NTP server

 

[color=rgb(0,0,0);font-family:arial, geneva, sans-serif;]The first step is to make sure you have the ntp program installed. Do a:[/color]

which ntpdate

[color=#000000][font="arial, geneva, sans-serif;"]Once ntp is installed synchronize your computer clock with:[/color][/font]

 

 

ntpdate pool.ntp.org 

[color=#000000]If ntp is not install, you may run this to install ntp[/color]

 

yum install ntp 

[color=#000000] To set time and date[/color]

 

date MMDDhhmmYYYY 

[color=rgb(102,102,102);font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:12px;]MM - Two digit month number[/color]
[color=rgb(102,102,102);font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:12px;]DD - Two digit date[/color]
[color=rgb(102,102,102);font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:12px;]hh - Two digit 24 hour system hour[/color]
[color=rgb(102,102,102);font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:12px;]mm - Two digit minute[/color]
[color=rgb(102,102,102);font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:12px;]YYYY - Four digit year code[/color]


Edited by Rand, 17 January 2015 - 11:34 PM.

 Click rep_up.png if you love your life:)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users


This topic has been visited by 15 user(s)