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.
Related
Is there a way to connect to my mysql database and do sth on tables via terminal?
Yes. In your terminal start the mysql prompt using
mysql --user=user_name --password=your_password db_name
Where db_name is the name of your database and user_name and password are your username and password.
You can then run SQL statements/queries from .sql files
mysql db_name < script.sql > output.tab
Where db_name is your database name, script.sql is a file containing your script, and output.tab (optional) is a file in which to dump the output of the query
You then simply place an SQL query in a file and run it.
If you get the error mysql: command not found, this is because the mysql executable cannot be found in your system PATH. If so, you need to run the following command to add the mySQL folder to the PATH, so that OS X knows to look there for the executable
export PATH=${PATH}:/usr/local/mysql/bin
Where /usr/local/mysql is the location of your mysql installation.
You can add this to your .bash_profile file (located at ~\.bash_profile, or you can create it) in order to have it run every time you start a new terminal. Otherwise you'll have to enter it manually before using the mysql command
Once you've entered this command (or added it to .bash_profile) you can use the mysql command as above
Alternately navigate to /usr/local/mysql/bin (or the location of your mysql install) and use the command
./mysql command
Instead of
mysql command
As above (where command is the command described in the first half of this post). This runs the mysql binary directly, rather than searching for it in the PATH
I recently tried to put my web application and mysql database on the same virtual server. Now I receive a port error. In order to fix the port issue, I want to back up the database and reinstall WAMP. Since I can't get to the phymyadmin, I have to use the mysql command prompt to do a dump.
Would anyone happen to know the EXACT command to put in, if my username is root, I have no password, and the database name is dev? I've tried it multiple ways and I get an error saying that my syntax is wrong.
Thanks in advance.
You can use the following command provided you know the name of the database:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Alternatively I would install the MySQL Workbench which can connect to your local database instance and provides a GUI to run the export: MySQL Workbench.
Unfortunately if you've uninstalled WAMP then MySQL might not be running anymore, and the above commands will not work because the utilities cannot see the database. If this is the case, try installing WAMP to a new directory and manually copying over the MySQL data files:
How to restore MySQL database from WAMP?
mysqldump -u root -p dev > devBackUp.sql
DOS batch file to export the database with date and time in the filename
FOR /f "tokens=1-8 delims=:./ " %%G IN ("%date%_%time%") DO (
SET dt=%%G%%H%%I_%%J_%%K
)
mysqldump -u root -p[root_password] [database_name]> [database_name]_%dt%.sql
pause
I just installed mysql 5.6 in a new CentOS 7 linux installation. I want to use the mysql command line client that I have been used to using in windows, but I cannot seem to find it. Is there a mysql command line client for linux? If so, how do I make sure that I have it? And how do I open it up in the GUI?
You can open MySql command line utility using following command
mysql -u user_name -p
It will ask for password for user_name. If password is not set call as follows
mysql -u user_name
First make sure the service is running :
sudo systemctl start mysqld
Then make sure to run the security script that will remove some dangerous defaults and lock down access to our database system a little bit.
sudo mysql_secure_installation
Now you can use the command line tool
mysql --user=user_name --password=your_password db_name
I am new to both linux and also mysql but somehow by obtaining help from net I have installed mysql v5.5 on redhat. It starts fine, I have confirmed this by running command:
"/etc/init.d/mysqld status"
But I am not able to change password using command:
mysqladmin -u root password 'new-password'
It gives error : bash: mysqladmin: command not found.
I tried searching mysqladmin by using command "find / -name mysqladmin" but it returned no result
All I can search on net is adding to path '/bin:/usr/local/mysql/bin' but directory structure after installation mysql v5.5 has changed. There is no such directory like /usr/bin/local/mysql now.
please help me with how to run mysql after changing root's password.
first of all see what MySQL packages are installed
rpm -qa | grep -i mysql
Second, try using locate in order to find the tool path
BTW,
According to pbone mysqladmin is provided by mysql-client (rather than mysql) as it was on older cackeages
Hi I have installed MySQL from oracle website, but did not get a "MySQL Command Line" option under MySQL in Programs menu.
So I looked up on this site how to execute sql queries from DOS command prompt.
I found an answer on this site that advised to type in something like: sql root u- p- etc. but this does not work.
Can anyone advise me the syntax to use to go into sql from DOS, or direct me to the answer described above (I cannot locate it)
I use Windows 7 and downloaded the ODBC driver, too.
Many thanks.
Unless MySQL's bin directory is in your PATH variable, you will need to either be in the directory, or write an absolute path to it to execute.
Try something like this (depending on your installation):
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -uroot
Alternatively, you could type this directly:
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" -uroot
cd/
cd wamp
cd bin
cd mysql
cd mysql5.0.51b
#################################
note use your own version of mysql, mine is 5.0.51b
########################################
cd bin
mysql -h localhost -u root -p
////////////////////////////////
note -p that is if u use a password
////////////////////////////////////////
after this line of codes you have this
welcome note telling you the server version of mysql and your connection id
If you navigate to the bin directory of the program you just installed then type "mysql.exe"
Have a look at this guide if you get stuck with the commands
Determine the path of your MySQL installation, and add it to PATH environment variable.
SET PATH=%PATH%;C:\MySQL\bin
The above example assumes MySQL to be installed in C:\MySQL directory.
Once path is set, then you can directly execute
mysql -u root
Which logs into MySQL as root user. The -p flag can be used if password is required
It is required to execute SET PATH every time, hence you may make a batch file.