I'm attempting to change the MySQL global variable datetime_format to use zulu time (%Y-%m-%dT%H:%i:%sZ) inside my application.
I've never had any issues running this command on localhost before and I cannot find a way to do it without receiving this error:
#1238 - Variable 'datetime_format' is a read only variable
On MAMP Pro I have access to the my.cnf file, but this doesn't let me set any default variables for startup.
Is there a way I can bypass this and/or set default variables when starting up MySQL or will I have to find an alternative local server?
To set datetime format, you need to add it inside your my.cnf file.
In MAMP you need to follow below steps:
Stop servers
Create a my.cnf file in /Applications/MAMP/conf/
Add your content in to my.cnf
Save my.cnf
Start servers
Related
Ive recently been playing with Mysql Workbench and the Export function has one little annoying feature that is not needed (by me of course). The set-gtid-purged function is set to AUTO by default in the GUI and it seems everytime you want to export without this parameter - you have to change it to OFF in Data Exports - Advanced options. To make it worse - the setting is not remembered.
Wanted to check if anyone has found a way to set it to OFF permanently for every DB/conenction i make?
I even checked the wb_options.xml file and the feature is set to OFF but this doesn't seem to stop it for some reason.
<value type="string" key="wb.admin.export.option:set-gtid-purged">OFF</value>
Thanks.
I've found a temporary solution for this on Linux/Ubuntu
Open /usr/lib/mysql-workbench/modules/wb_admin_export.py
Search for "--set-gtid-purged=OFF"
Delete or comment that line (#) and the if statement above it.
Restart MySQL Workbench
Using windows, the path to the file will vary and I will update my answer if someone can give it to me.
I want to do exactly what you are looking for but in AWS RDS. so for your case what you must do is:
Solution
Update config file Update /etc/my.cnf and add
[mysqldump]
set-gtid-purged=OFF
No need to restart. If you dont have access to that .cnf file then update the update directadmin.conf with the following instruction:
extra_mysqldump_options=--set-gtid-purged=OFF
Is possible to run the following command in shell to achieve point number 2:
echo "extra_mysqldump_options=--set-gtid-purged=OFF" >> /usr/local/directadmin/conf/directadmin.conf
service directadmin restart
Official and useful references
MySQL Dump
MySQL enable/disable GTID (Global Transaction Ids)
MySQL extra options during DUMP
On a Mac, running Mysql 5.7, I found the following to work:
In Workbench, select:
Server -> Data Export -> Advanced Options
change "set-gtid-purged - Add 'SET ##GLOBAL.GTID_PURGED' to the output." from AUTO to OFF
Then export your data.
The exported SQL files should no longer have the line:
"SET ##SESSION.SQL_LOG_BIN= 0;"
and now it imports successfully.
If you are using only mysqldump in Ubuntu Server
Try append this to etc/mysql/conf.d/mysqldump.cnf
set-gtid-purged=OFF
column-statistics=0
May looks like this:
I have a MySQL server (version 5.0.67) running on Windows 7. While I was working with hibernate within Eclipse, I got the following error:
Caused by: java.sql.SQLException: Can't create/write to file 'C:\Windows\TEMP#sql_e9c_0.MYI' (Errcode: 17)
I tried to configure the TmpPath of MySQL and set Systemparameters to TMPDIR:
TEMP=C:\Users\JDD09~1.HER\AppData\Local\Temp
TMP=C:\Users\JDD09~1.HER\AppData\Local\Temp
TMPDIR=C:\tmp\tmpdir
Within my.ini, I made the following change:
[mysqld]
tmpdir=C:\tmp\tmpdir
However, now MySQL aborts when it tries to start up.
I've read this thread (Changing the tmp folder of mysql), but it didn't help. How can I fix this?
You may need to make sure you are using forward slashes '/' instead of backward slashes '\'. This worked for me, so you would use this line:
tmpdir=C:/tmp/tmpdir
Try this:
[mysqld]
tmpdir="C:\tmp\tmpdir"
and make sure that path C:\tmp\tmpdir must exist in the system.
According to the manual for Mysql 5.0 as regard 'TMPDIR': 5.0/en/windows-installation.html. The default is to use the windows temporary directory.
If you decide to define it. Then it must be a valid directory. It will not create it.
My recommendation, for a 'development' system on a local pc is not bother changing it.
If you are not sure then delete the entry from 'my.ini'. This will use the default settings which should be ok to get you started.
ps. i use 'mysql' on windows.
According to the documentation:
On Windows, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.
If the file system containing your temporary file directory is too small, you can use the mysqld --tmpdir option to specify a directory in a file system where you have enough space.
The --tmpdir option can be set to a list of several paths that are used in round-robin fashion. Paths should be separated by colon characters (:) on Unix and semicolon characters (;) on Windows.
Edit the file C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
Add the following line, under [mysqld]
[mysqld]
tmpdir=C:/tmp/tmpdir
Restart MySQL service under Windows services.
Change can be verified by the following commands in windows prompt
mysql -uroot -p -e "SHOW VARIABLES LIKE 'tmpdir'"
I come from the oracle world where the tnsnames.ora file contain all the sql connection information.
I cannot seem to find the file containing such information for mysql. Could someone with a windows machine tell me where I can find it please.
MySQL doesn't need a connections file analogous to the .tns file. MySQL has nothing like a TNS. Connection parameters typically are configured explicitly in your application.
You can optionally create a file called .my.cnf that contains a user's default parameters for connecting.
See also What is the location of mysql client “.my.cnf” in Windows? that shows how to use mysql --help to find out the location of all the config files.
Most people just configure one set of connection parameters in their .my.cnf file, but you can configure multiple sets of connection parameters under different [client] groups, and invoke MySQL client tools to use the respective connection. There's an excellent blog that describes how to set this up here: http://datacharmer.blogspot.com/2011/03/hidden-options-file-trick.html
Re your updated info:
Sorry, I had to boot up a Windows box and install MySQL Workbench to check where the connection info is stored. I don't normally use Windows.
Right, for MySQL Workbench, the connection data is in for example,
C:\Users\Uncle Iroh\AppData\Roaming\MySQL\Workbench\connections.xml
But you're not expected to edit this by hand, and you'll probably ruin it if you try. It's undocumented, and presumably the format could change if you change versions of MySQL Workbench. You should create or edit connections in the Workbench GUI.
There is no such thing in MySQL. Check for a config file called my.ini or my.cnf. If MySQL is using a non-default port (not 3306), it will be detailed there. Otherwise, connect using:
mysql -u user -p
This is an executable (mysql.exe) you'll find in the bin directory of the installation (probably). For example, on my Windows box it's here: C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysql.exe
I am trying to set my Mysql mode using this. It works, but when the server is restarted it defaults back to STRICT_TRANS_TABLE, NO_ENGINE_SUBSTITUTION. How can I make it permanent so it stays this way after a restart.
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Alter your mysql configuration file. The file is called my.cnf if in windowzzz look for the my.ini
Append the following line to it and restart your mysql engine after
sql-mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION"
I tried to load a file into a MySQL blob (on a Mac).
My query is
INSERT INTO MyTable VALUES('7', LOAD_FILE('Dev:MonDoc.odt'))
No error appears but the file is not loaded into the blob.
The manual states the following:
LOAD_FILE(file_name)
Reads the file and returns the file contents as a string. To use this
function, the file must be located on the server host, you must
specify the full path name to the file, and you must have the FILE
privilege. The file must be readable by all and its size less than
max_allowed_packet bytes. If the secure_file_priv system variable is
set to a nonempty directory name, the file to be loaded must be
located in that directory.
If the file does not exist or cannot be read because one of the
preceding conditions is not satisfied, the function returns NULL.
As of MySQL 5.0.19, the character_set_filesystem system variable
controls interpretation of file names that are given as literal
strings.
mysql> UPDATE t
SET blob_col=LOAD_FILE('/tmp/picture')
WHERE id=1;
From this, I see more than one thing that could be wrong in your case...
are you passing the full path?
are privileges set correctly?
what does the function return? NULL?
have you tried it with the query given in the manual?
I had the same problem with Linux ...
select load_file('/tmp/data.blob');
+-----------------------------+
| load_file('/tmp/data.blob') |
+-----------------------------+
| NULL |
+-----------------------------+
Eventually i could load the file successfully after user and group ownership were changed to 'mysql':
sudo chown mysql:mysql /tmp/data.blob
double escape the slahes in the full path if you're in windows.
I just wanted to add one more caveat that I found in my testing:
when using select load_file('/path/to/theFile.txt'); The file that you are loading HAS to be on the machine the sql instance is running on.
This bit me in the butt for a long time because I use MySQL workbench to load files all the time into our various sql instances and when using commands like LOAD DATA LOCAL INFILE 'C:/path/to/theFile.csv' INTO TABLE those would easily grab the file off of my local hard drive and process it into the tables regardless of where the actual sql instance was running. However the load_file command doesn't seem to behave at least for me in the same way (Maybe there exists a local_load_file() command I don't know about). MySQL seems to only allow it to look for files from the local system where the sql instance is running.
So if you're like me and you can't figure out why load_file is always returning NULL have no fear...upload the files to the sql server instance and then use that path from your Query browser and all will be well.
After ensure other conditions, my solution is change a global variable named secure-file-priv. Its default value is NULL, which means mysqld can't read/wirite files.
I changed its value by add secure-file-priv= in /etc/my.cnf behind [mysqld], then restart mysql service. Then,
load_file() worked!
Thanks.
The user that is running mysql, needs to OWN the file. My mistake was, I thought it just needed to be able to READ or EXECUTE the file.