CONVERT_TZ function not working: Time zone data for MySQL - mysql

I am trying to use the CONVERT_TZ in MySQL. From what i have looked up the time_zone tables in the mysql schema need to be populated. I have looked this up on many different site and followed a few tutorials including this tutorial but the tables are still not populated
The 15 timezone files have been added to my C:\Program Files\MySQL\MySQL Server 5.6\data\mysql directory.I have tried both to add these files manually and use the mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql as seen here. I have restarted the MySQL service but the tables have still not been updated both ways
Does any have any ideas why?

Solution :
I found the answer to this here. It seemed that even do I had a folder structure of C:\Program Files\MySQL\MySQL Server 5.6 when i ran the command show variables like 'datadir in MySQL it was pointing to C:\ProgramData\MySQL\MySQL Server 5.6 which is a hidden folder so i did not see it before
When i added the timezone files to C:\ProgramData\MySQL\MySQL Server 5.6\data\mysql it worked

Related

cannot find mysql slow query log file on mac

I am trying to enable slow_query_log on mysql, but I could not find it on my mac.
I read in MySQL 5.7 Documentation that"
By default, the server writes files for all enabled logs in the data directory.
When I write show variables like '%slow_query%'; in mysql shell, I see the following:
but I can't see McBook-Pro-6-slow.log in the data directory. Here is all I can see in the data directory:
Could someone let me know why I can't see the slow log file?
In order to enable the slow_query_log, I've read here that I should add slow-query-log=1 to my.cnf. Here, my problem is that I am not sure where is mysql config file on my Mac. I've found a my-default.cnf in usr/local/mysql/support-files/ and another my.cnf file in /etc. Which one should I modify??
Thanks,
Refer to this Stackoverflow question MySQL 'my.cnf' location? which pertains to Mac OS. As you can see the permutations of locations are numerous usually compounded by different distros and MAMP XAMP WAMP bundles and Home Brew. It is not uncommon to have 2 mysql daemons on a box and not even know it.
Which is why in comments I suggested looking at the output of select ##basedir for the location of the my.ini (Windows) or my.cnf (Linux/Mac). That is not to suggest a configuration file is going to be there, but that is where it should be if one were to exist. Without it, baked-in default values are used. Often there is a stub, a suggested file, named differently (like my-default), awaiting your tweaks and a rename or copy to the appropriate file name of my.ini or my.cnf.
There is also a system variable named slow_query_log_file and its value visible if set thru SELECT ##slow_query_log_file;. For me right now it has a value of GUYSMILEY-slow.log because I did not set it in my ini (Windows) and it defaults to computername+"-slow.log".
That is the filename without the path. Where the file actually is written to is in the datadir seen with the output of select ##datadir;.
On my system this means (via ##basedir)
C:\Program Files\MySQL\MySQL Server 5.6\my.ini
would have a setting that ends up in a slowlog file written to in this absolute path (helped by ##datadir):
C:\ProgramData\MySQL\MySQL Server 5.6\data\GUYSMILEY-slow.log
and a fragment inside that log file might show something like this:
Ini and cnf changes require a MySQL daemon restart. In that configuration file a section similar to (my 5.6)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.6\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.6\\Data\\
port=3306
log_warnings = 2
and (my 5.7)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data\\
port=3307
log_error_verbosity=2
the above is used within the [mysqld] section to play with settings. What I suggest is playing with this section with an innocuous setting like log_error_verbosity (5.7.2 and up) or similar, save it. Restart the deamon and determine if the variable (as Rick James would call settings because most really aren't dynamically settable). So a sanity check of select ##log_error_verbosity (5.7.2 and up) can confirm it the change is picked up. If it is, bingo, you are doing it right.
The Manual Page Server System Variables depicts the variables (settings) and whether or not they can be dynamically set/changed after the config file load via commands. Dynamic changes are reverted upon daemon restart.
How one would dynamically change a variable might look like:
SET GLOBAL log_error_verbosity=2;
Again, only certain variables are available in certain MySQL versions, such as the above, not available in older versions.
Also note multiple versions of MySQL running concurrently on a server. On mine i have 5.6.31 and 5.7.14. To access a different one via command line tools, use something like the -P 3307 switch to point at the one running on port 3307. Note the uppercase P as opposed to lowercase (which would mean prompt for password).
Determine if multiple instances are running. I use port checks such as
sudo netstat -tulpn (Linux)
netstat -aon | more (Windows, the top part, State=LISTENING)
Unfortunately these types of changes and trial and error take time and are very frustrating. Sorry I do not have a quick and easy answer for all cases.
Addendum
Notes here related to comments. In the below, w-x-y-z is a redacted IP Address.
On a Linux box (amazon ec2 redhat btw):
select ##slow_query_log;
-- 0 (so it is turned off)
SELECT ##slow_query_log_file;
-- /var/lib/mysql/ip-w-x-y-z-slow.log
select ##version;
-- 5.7.14
set global slow_query_log=1;
Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation 0.094 sec
(ok I was in MySQL Workbench as a dummied down user, off to do it as root via MySQL cmd line ...
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> select ##slow_query_log;
+------------------+
| ##slow_query_log |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
btw Workbench user can confirm the above `1`
at shell as linux user:
[ec2-user#ip-w-x-y-z ~]$ cd /var/lib/mysql
[ec2-user#ip-w-x-y-z mysql]$ sudo ls -la
(there were many files, only one needed to show you below)
-rw-r-----. 1 mysql mysql 179 Sep 19 01:47 ip-w-x-y-z-slow.log
[ec2-user#ip-w-x-y-z mysql]$ sudo vi ip-w-x-y-z-slow.log
(Header stub, the entire contents, no slow queries yet, log seen below):
/usr/sbin/mysqld, Version: 5.7.14 (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
SHOW VARIABLES LIKE 'log_output'; to verify that it is set to FILE or FILE,TABLE.

Dump File MySQL 5.6.10

I was trying to create a dump file from my MySQL database, but when I try it always gives me this error
Operation failed with exitcode 2
16:06:07 Dumping proactivetraindb (userstate)
Running: mysqldump.exe --defaults-extra-file="h:\docume~1\anarita\locals~1\temp\tmpde5rwy.cnf" --user=root --max_allowed_packet=1G --host=localhost --port=3306 --default-character-set=utf8 "proactivetraindb" "userstate"
mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': 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 'OPTION SQL_QUOTE_SHOW_CREATE=1' at line 1 (1064)
The version of MySQl is 5.6.10 but the version of MySQLDump is 5.5.16
Does someone know how to solve this?
As outlined by a previous answer, but just to clarify further: This is for MySQL in Windows.
I was having the exact same issue while trying to dump data out of a table on a local test server, and based on the previous answer, this is how I did it.
Find your mysql original download folder, and look in the /bin folder, there should be a mysqldump.exe.
Go into Workbench Preferences: Edit -> Preferences -> Administrator -> Path to mysqldump Tool, and enter in the path to the mysqldump.exe that you found.
Save by pressing "OK" and restarting Workbench.
Open up terminal, but typing in cmd in the Search area of the start menu (Windows 7), and find the sql folder you found in step 1, and cd into bin. It should look like C:\...\bin>. Here, type in mysqldump -t -u [username] -p [database name] [tablename]. This should dump the data from the [tablename] table into the dump folder as designated in Workbench.
Hope this helps!
I had the same error in MySQL Workbench.
Find out where is the mysqldump tools provided by your install of MySQL 5.6. On my mac it was at "usr/local/mysql-5.6.10-osx10.7-x86_64/bin/mysqldump".
Then I set up this path in MySQL Workbench/Preferences/Administrator/Path to mysqldump Tool
Give MySQL Workbench a restart.
It should work.
The reason for this is that MySQL 5.6 has removed support for "SET OPTION" and your mysql client tools are probably on older version. Most likely 5.5 or 5.1. There is more info about this issue on MySQL bugs website.
The quickest solution is to update your mysql client tools to 5.6 and your problem will be solved. If you are on Linux platform, here is a solution that worked great for me:
http://www.markomedia.com.au/mysqldump-mysql-5-6-problem-solved/
You must use mysqldump 5.6.x to be able to dump mysql 5.6 database, because MySQL 5.6 discontinued and removed support for SET OPTION syntax.
Under 32/64bit Windows you must do:
1.1. (32bit win) Download Windows (x86, 32-bit), ZIP Archive 5.6.19 212.3M http://dev.mysql.com/downloads/mysql/ (direct link http://dev.mysql.com/downloads/file.php?id=452188)
1.2. (64bit win) Download Windows (x86, 64-bit), ZIP Archive 5.6.19 217.2M http://dev.mysql.com/downloads/mysql/ (direct link http://dev.mysql.com/downloads/file.php?id=452189)
2. Extract mysqldump.exe from just downloaded file mysql-5.6.19-win32(64).zip (from /mysql-5.6.19-win32(64)/bin/mysqldump.exe)
3. Replace this just extracted file with your already installed mysqldump.exe file (instalation dir/mysql/bin/mysqldump.exe)
Using Windows 7, a far easier solution for me was to find mysqldump.exe from; C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe
copy it and then replace the MySQL workbench mysqldump.exe which is located in the root of workbench C:\Program Files\MySQL\MySQL Workbench CE 5.2.47\mysqldump.exe
Restart MySQL workbench and all should work fine.
You are probably using Amazon RDS, right?
You can just get the newer version of mysqldump, v5.6 and use it instead.
Download the portable zip here and extract just the mysql\mysqldump.exe there.
http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/1.8.3/
I tried it just now and it worked fine for me.
If you are using Window 10. Your Mysql server would have been installed in C:\Program Files\MySQL directory and rest all components are installed in C:\Program Files (x86)\MySQL.
Go to MySql Workbench>Edit>Preferences. A window will open, click the Administrator tab and mention the path of your mysqldump.exe (which is present in C:\Program Files\MySQL). Restart your workbench.
Thanks, Happy coding!!
In Workbench look for Preferences: Edit -> Preferences -> Administrator -> Path to the mysqldump Tool. Browse your MySQL folder inside the bin folder and look for mysqldump.exe.
I had this problem on the Amazon EC2 acessing a RDS Mysql 5.6 database. I just ran
sudo apt-get upgrade
It didn't update mysql client to 5.6, but mysqldump now is working fine.
For Mac it depends on your installation.
If you used a dmg file to install it, you need to find the bin directory.
mine was under /usr/local/mysql/bin
You will find mysqldump file under this folder.
Now provide this location in your
Preferences -> Administrator -> Path to mysqldump Tool as /usr/local/mysql/bin/mysqldump
You should be good to export now.
If you are on Linux, update mysql-client to latest version. On Ubuntu:
sudo apt-get upgrade mysql-client
did the job for me.
Setting up mysql-client-5.5 (5.5.43-0ubuntu0.12.04.1) ...
Mine got updated to 5.5 and mysqldump now works for me. This is on Amazon RDS with MySQL 5.6.x
If you're on a linux machine, this is provided by the mysql-client package. Installing that fixed the problem for me.
For compatibility, I needed MySQL 5.6.41 on my Windows 10 machine, so I used the 5.6.41 MySQL installer to install "All" (My Workbench, MySQL, connectors, etc).
Even though I used the installer for version 5.6.41, it installed Workbench 8.0, as well as version 8.0 of the various connectors, etc.
So of course, I got a similar error.
There seems to be no easy way to force lower version of MySQL Workbench to be installed instead (On my previous machine, before workbench 8.0, did NOT have this conflict when installed).
Solution that worked for me:
Find the version of mysqldump.exe that matches the version of MySQL you're using:
From Windows Explorer, I searched my machine for all versions of mysqldump.exe
Right-clicked each mysqldump.exe it found -> Properties -> Details tab.
Found the version 5.6.41 (matching the MySQL version I'm running)
Clicked back to the General tab, to see the folder path that that version of mysqldump.exe was installed in
C:\Program Files\MySQL\MySQL Server 5.6\bin, in my case
(version 8.0 was installed in C:\Program Files\MySQL\MySQL Workbench 8.0 CE)
Now open MySQL Workbench..
Edit -> Preferences -> Administration -> Path to mysqldump Tool
Paste in the file path for the appropriate version of mysqldump.exe (including the file name!)
Click OK
Restart MySQL Workbench
This worked for me. However, I have no idea how to make this work if you have two versions of MySQL on your machine, say MySQL 5.6 and 5.7, or 8.0.
So when I upgrade (any/some/all of) my cloud servers to version 5.7, this looks to be another challenge to overcome. Since Workbench only allows a single mysqldump.exe file, to be used no matter which version of my local MySQL server is running... Or perhaps manually change the path location, each time open a connection that uses the Port to the other MySQL version (and remember to change it back after?).
For this reason, I Removed MySQL 5.7 completely, and will hence keep all cloud (and my local) servers at 5.6 for the time being - a Project for another day.
For Ubuntu users to save your time, mysqldump is in "mysql-community-client_5.7.26-1ubuntu16.04_i386.deb " package
I just had the same problem and I put a couple of different answers together.
The pro for me was, that I could switch easily between 5.6, 8, ... without having to up/downgrade ubuntu dependencies each time.
The easiest way for me on Ubuntu was to just download the 5.6 (or 5.7, whatever you want) mysqldump binary and change that in workbench.
Everything went well after that:
go to https://downloads.mysql.com/archives/community/ and download the correct version you want (for me: 5.6.47 for 64x)
Unpack the archive somewhere, you can find later
Change the mysqldump binary in mysql workbench: Edit -> Preferences -> Administrator -> "Path to mysqldump Tool" to {{YOUR_UNPACKED_FOLDER}}/bin/mysqldump
Save it with Ok
Now you should be able to just export and it will use mysqldump 5.x.
I have Mysql 5.6.12 version. SET SQL_QUOTE_SHOW_CREATE=1 is working fine in my machine.
now i am able to take a dump of sql.
mysql> SET SQL_QUOTE_SHOW_CREATE=1; Query OK, 0 rows affected (0.00
sec)
worked for me.

convert_tz returns null

I know this sounds stupid, but when I use
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta') AS time
it outputs NULL. I'm using MySQL Workbench in Ubuntu 12.04 64 bit, and it works in my other laptop/os (also using MySQL Workbench).
This will happen if you haven't loaded the time zone table into mysql.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql is the name of the built-in database that holds MySQL-specific configuration data.
I found this thread after spending some time trying to figure out why after running the command in the accepted answer (which is the same on MySQL's dev site) the command was unable to convert between timezones such as
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','MET') AS time
It turns out that on OS X there are two files that cause problems: /usr/share/zoneinfo/Factory and /usr/share/zoneinfo/+VERSION.
The fix... temporarily moving these files to a different location such as /usr/share/zoneinfo/.bak/ allows for the command
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
to fully populate all of the expected timezone information.
This may or may not be a bug in my installed version of MySQL:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.11, for osx10.6 (x86_64) using EditLine wrapper
I am also operating in STRICT_MODE.
In any case, I hope this saves a few headaches for anyone searching for the fix.
Apart from Windows environment, You can set Time Zone by
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
In Windows environment,
1. download Time zone description tables from http://dev.mysql.com/downloads/timezones.html
2. Stop MySQL server
3. Put then inside Mysql installation package (ie. C:\Program Files\MySQL\data\mysql)`
4. Start MySQL server
..Your work is finished..
If still you are getting NULL for CONVERT_TZ
Download these database tables and insert it into mysql database http://www.4shared.com/folder/Toba2qu-/Mysql_timezone.html
Now you problem will be solved.. :)
MAMP PRO
Open Terminal
cd /usr/share/zoneinfo/
sudo mv +VERSION ~/Desktop
cd /applications/MAMP/Library/bin
sudo ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
sudo mv ~/Desktop/+VERSION /usr/share/zoneinfo/
1) In Windows, there isn't any data folder now in C:\Program Files\MySQL\ as in other answers.
2) In that case, look for C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql. Generally this folder hidden and you will not see C:\ProgramData\ some times.
3) Change the Settings in View tab to see Hidden files and Folders as explained here https://irch.info/index.php?pg=kb.page&id=133
4) Stop the MySQL service by searching for "services" in Windows Start button.
5) Then unzip the timezone_2017c_posix.zip and then copy the files in it (copy the files directly, don't copy the whole folder itself), and paste in
C:\ProgramData\MySQL\MySQLServer5.x\Data\mysql\
6) For MySQL 5.7, timezone_2017c_posix.zip will just give a .sql file after unzipping and it may not solve the issue. So go ahead and download the zip file for 5.6 even if you are running MySQL 5.7 and copy those files to C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql\
7) Restart the MySQL server. To check if the CONVERT_TZ () is working, run this sql query.
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta');
and check for non-null output.
These are the steps to make it work if you're in windows and using MySQL 5.7.
Right click on My Computer/Computer/This PC or whatever the name in your OS and choose Properties.
Choose "Advanced system settings" from the left panel.
Choose "Environmental Variables", enter the complete path name of your MySQL bin directory (generally it will be in, C:\Program Files\MySQL\MySQL Server 5.7\bin).
Open cmd prompt, enter into mysql using mysql -u root -p password.
Enter use mysql to select the MySQL DB.
Download the file "timezone_YYYYc_posix_sql.zip" (In the place of YYYY, substitute the maximum year available in that page like 2017 or 2018) from https://dev.mysql.com/downloads/timezones.html.
Extract it and open the file in text editor.
Copy the contents and execute in the cmd prompt.
On successful completion, you should be able to use CONVERT_TZ and other timezone functions.
If you are using MySql on Windows you have to load the timezone data into the mysql schema. Here is a good HOWTO: http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html
If you don't do this, the function CONVERT_TZ won't recognize your input timezone (i.e. your examples: 'UTC','Asia/Jakarta'), and will simply return NULL.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
if you get the error data too long for column 'abbreviation' at row 1
then see: https://bugs.mysql.com/bug.php?id=68861
the fix would be to run the following
this will add a line to disable the mysql mode and allow mysql to insert truncated data
this was because of a mysql bug where mysql would add a null character at the end (according to the above link)
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
(if the above gives error "data too long for column 'abbreviation' at row 1")
mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/zut.sql
echo "SET SESSION SQL_MODE = '';" > /tmp/mysql_tzinfo_to.sql
cat /tmp/zut.sql >> /tmp/mysql_tzinfo_to.sql
mysql --defaults-file=/etc/mysql/my.cnf --user=verifiedscratch -p mysql < /tmp/mysql_tzinfo_to.sql
On Mac OS Catalina when using XAMPP,
Go to /Applications/XAMPP/xamppfiles/bin folder in Terminal then run following.
./mysql_tzinfo_to_sql /usr/share/zoneinfo | sed -e "s/Local time zone must be set--see zic manual page/local/" | ./mysql -u root mysql
This worked for me.

Location of database tables - MySQL - Windows XP

All,
This is the first time I am using MySQL and hence listing all the steps. This is actually a reinstall of MySQL since my 1st attempt had failed.
I have installed the latest version of MySQL Community Server on my machine. The installation folder is C:\Program Files\MySQL\MySQL Server 5.5 . The data folder resides in this folder path itself. I have created few tables in the MySQL command prompt by:
1 > Going into MS DOS Prompt.
2 > Making C:\Program Files\MySQL\MySQL Server 5.5 as my current directory
3 > Entered command: mysql -u root -p
4 > Entered password
5 > Placed my script file(.sql) which creates new tables in the folder C:\Program Files\MySQL\MySQL Server 5.5\bin
6 > In the command prompt, typed source <scriptfile>.sql
7 > Now, I get warnings for few tables. But when I enter command SHOW TABLES, all the tables in the script file are shown.
However, I am not able to locate the tables created in form of directories/files on the drive. The data folder does not contain my tables as well.Can anyone please tell me where are the tables located?
On Windows 7, the data directory is, by default, "C:/ProgramData/MySQL/MySQL Server 5.5/Data/". Note that "C:/ProgramData" is a hidden directory.
In windows 8(dont check in other OS)
Enter mysql in command prompt by
mysql -uusername -ppassword
Then type
select ##datadir;
mysql> select ##datadir;
+---------------------------------------------+
| ##datadir |
+---------------------------------------------+
| C:\ProgramData\MySQL\MySQL Server 5.6\data\ |
+---------------------------------------------+
1 row in set (0.00 sec)
Another way!!!
Go to C:\ProgramData\MySQL\MySQL Server 5.6\my.ini and there you can find datadir.
Be sure it is in ProgramData, not in ProgramFiles.
Go into your C:\Program Files\MySQL\MySQL Server 5.5\my.ini and find the variable "datadir".
This is your Data dir ;)
the table files are located in the \data folder. if you have not overriden this path when you were installing or if you have not modified the path in the my.ini config file after the installation. there are gui tools available for mysql that can help you do things easily.
C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/
Is the default DATA directory in XP.

Where do the MySQL database files reside for WAMP?

I'm just curious as I am beginning to learn PHP and MySQL, as to where the database and other files of MySQL reside on the hard drive. I have installed WAMP on a Windows XP SP2 platform.
Explore variables from the output of following command:
mysql> show variables like '%dir%';
Data directories for mysql database :
Generally,
Windows wamp setup : mysql/data
Linux (Ubuntu) : /var/lib/mysql
Configured Location: [ my.cnf configures it as datadir ]
Linux :
$ cat /etc/mysql/my.cnf | grep 'datadir'
Windows :
Open mysql/my.cnf (search for `datadir` )
From mysql prompt : ( mysql> ) [ PREFERRED WAY ]
mysql> show variable like 'datadir';
I suppose that covers pretty much all cases.
Usually in the /mysql/data directory of your WAMP installation. You'll recognize the location because every database has a folder with the same name there.
You can change the location of the data directory using the datadir setting in my.cnf. It is often moved elsewhere to ensure the data there gets backed up regularly.
I am not sure about WAMP, but if you install MySQL manually it should reside somewhere along the lines of this path:
C:\Program Files\MySQL\MySQL Server 5.1
Use the following to find the data directory using SQL console:
show variables like 'datadir'
If your on linux you can use:
sudo find / mysql | grep mysql
On Ubuntu it stores its database files in /var/lib/mysql
wamp/bin/mysql/mysqlx.x.x/data