Change default sql mode - mysql

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"

Related

error #1238 when updating datetime format variable

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

How to set default collation for mysql xampp, windows

Hi I ran into this question and could not get an answer. How can you set default, server-wide collation for your MySQL database for XAMPP+Windows.
What I have figured out. Look for my.ini file in your mysql folder, bin subfoler (e.g. E:\xampp\mysql\bin). Backup your my.ini file and open it for edit, then look for following:
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
Here you can change your collation to the desired default value. Save edits and restart MySQL.

Q: How to set --set-gtid-purged=OFF as a default Export parameter in Mysql workbench?

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:

How to enable Event Scheduler when I open MySQL Server

I have a problem with Event Scheduler. It is disabled automatically when I restart the MySQL Server. How can I enable the event scheduler automatically when I restart the MySQL Server.
I have red one solution after a long search, i.e enable the Event Scheduler in my.ini file in MySQL with the following command.
event_scheduler=on
If I make changes in my.ini file with the above command it displays an error while saves the my.ini file like 'access denied'.
Is there any problem in my above process? If there is, any solution for this problem?
Thanks in advance.
It is a problem with your privileges in windows and not with mysql, just open the file with notepad which runs with administrator privileges. Right click notepad and chose "run as administrator", then open your my.ini file and edit it.
You can set
SET GLOBAL event_scheduler = ON;
(or)
SET GLOBAL event_scheduler = 1; // in my.ini or my.cnf file.
Then restart your server for the setting to take effect.
Once set 'event_scheduler' will always remain 'ON' no matter whenever your server restarts

Where to change the value of lower_case_table_names=2 in XAMPP on Windows?

I am using Windows 7 and XAMPP. I am trying to export my database and while in the process the table names are converted to lower case.
I have searched a lot, I know I have to change the value of lower_case_table_names from 0 to 2, but where do I have to change this value, in which file?
Do these steps:
open your MySQL configuration file: [drive]\xampp\mysql\bin\my.ini
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 2
save the file and restart MySQL service
From: http://webdev.issimplified.com/2010/03/02/mysql-on-windows-force-table-names-to-lowercase/
On linux I cannot set lower_case_table_names to 2 (it reverts to 0), but I can set it to 1.
Before changing this setting, do a complete dump of all databases, and drop all databases. You won't be able to drop them after setting lower_case_table_names to 1, because any uppercase characters in database or table names will prevent them from being referenced.
Then set lower_case_table_names to 1, restart MySQL, and re-load your data, which will convert everything to lowercase, including any subsequent queries made.
Try adding/editing lower_case_table_names = 2 in my.ini or my.cnf
I have same problem while importing database from linux to Windows.
It lowercases Database name aswell as Tables' name.
Use following steps for same problem:
Open c:\xampp\mysql\bin\my.ini in editor.
look for
# The MySQL server
[mysqld]
3 . Find
lower_case_table_names
and change value to 2
if not avail copy this at the end of this [mysqld] portion.
lower_case_table_names = 2
This will surely work.
Also works in Wampserver.
Click on the Green Wampserver Icon, choose MySql, then my.ini.
This will allow you to open the my.ini file.
Then -
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 2
save the file and restart MySQL service
Important Note - add the lower_case_table_names = 2 statement NOT under the [mysql] statement, but under the [mysqld] statement
Reference - http://doc.silverstripe.org/framework/en/installation/windows-wamp
If you have the file my-default.ini rename it to my.ini
ADD following -
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 1
In file - /etc/mysql/mysql.conf.d/mysqld.cnf
It's works for me.
Look for a file named my.ini in your hard disk, in my system it's in
c:\program files\mysql\mysql server 5.1
If it's not my.ini it should be my.cnf
On Mysql Server 8.0 Windows os, if you change lower_case_table_names=2 in mysql.ini the server will not start so you have to follow this
1: Backup all data / export to .sql or Dump all data
2: Stop the server from service
3: Delete the data folder from C:\Program Files\ Mysql Server 8.0\Data
4: Open C:\Program Files\ Mysql Server 8.0\my.ini as an administrator using notepad
5: find set lower_case_table_names= 2 if you want camelCase table name
6: open mysql installer and open reconfigure then open ->show advanced and logging option -> Advanced Options -> use second option from the list
7: then everything will be ok