Why can't I change sql_mode permanently? - mysql

I an currently using mysql server 5.6 in windows 10. while using mysql, an error keeps appearing that goes as something like this "the following column does not have a default value" i read on the internet that i can solve this problem if i change the sql_mode. It is currently set to
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
I took this from "my-default.ini" file in "mysql server 5.6" folder. I read several other answers that say that if you want to permanently change your sql_mode, you should do it through the "my-default.ini" file. So what i did was, i run my notepad as administrator, then i browsed to open "my-default.ini" file that is found in:
c:\programs files (x86)\mysql\mysql server 5.6\my-default.ini
when i opened the file, i modified the last line:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
to
sql_mode=
then i saved the file, closed it. then by using task manager i restarted my sql sever:
task manager >> services >> mysql56
This is the whole process that should permanently modify my sql_mode. when i look in my "my-default.ini" file, the last line is still modified. but if i log into mysql through the command line and view my sql_mode with the following code:
select ##sql_mode;
I get that my sql_mode is
STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
I want all this to be removed (permanently) in order for my error to disappear. IF i try to modify the sql_mode from the command line by using:
set ##global.sql_mode="";
It worked, but when i restarted MySQL, everything was back as it was before.
Can someone please tell me what i am doing wrong? and if there is another way to solve this problem.

UPDATE: Sorry, forgot you were using Windows 10. I'm not sure how to deal with this issue in Windows but maybe try copying my-default.ini to my.ini and changing that setting. Sorry for confusion.
Not sure if you can set your sql_mode to nothing but try changing the value in your /etc/mysql/my.cnf file. If that folder/file doesn't exist, create it and try setting sql_mode under [mysqld] like this:
[mysqld]
sql_mode=
I just did this same thing only I set the sql_mode to NO_ENGINE_SUBSTITUTION.

If you have MySQL Workbench installed, check the Server Status for the base directory of your instance. You should find a my.ini file there that keeps your changes.

sql_mode need to add to file /etc/init.d/mysql as a argument to start like:
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" --sql-mode="" $other_args >/dev/null 2>&1 &
Restart MySQL database server to apply new config.

In MYSQL 8 and ubuntu server 20.xx I had to add:
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTIO
To file
/etc/mysql/mysql.conf.d/mysqld.cnf
In order that the setting stay persistent after server restart
Disclaimer:
this was the only place it actually worked, I have no idea what's the good practice where to add these custom settings but it 'ain't stupid if it works'. Somebody can tell me.
I tried the other options I found on forums:
my.cnf did not work creating
custom cnf did not work
adding it to mysql.cnf did not work

Related

Where does the my.cnf resides on macOS High Sierra?

I wanted to disable some options in the MySql server strict mode, but for some reason I'm not even able to find its configuration file (my.cnf)
Currently installed MySql:
Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64)
Output generated by
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
But there is no such file as my.conf
I had done some research work on SO but none of the advises has worked for me.
What I'm supposed to do?
There are defaults built into MySQL. The configuration file(s), if any, override the defaults.
Note that the config files are not looked at except during startup. So, editing or creating such a file has no effect until you restart mysqld.
If you mess up the syntax, mysqld will not start. Then you need to find the error, either during startup, or in a log file. (Or you could ask here "what is my syntax error".)
As for the location, and name, of the config files that will be used:
$ mysql --help
gives you the list for mysql, but perhaps you need it for the server, so try
$ mysqld --help --verbose
gives you long output; maybe 50 lines from the top, you should see something like:
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
You asked about my.conf; was that a typo?
Regardless, If those files are missing, you can create them, make them readable by mysql, and put things into it preceded by [mysqld] so that the server will see them.
Personal override
Regardless of what is in the defaults and/or config files, you can add to the last file given. In the examples above that is 'hidden' .my.cnf in your home directory. All you need to do is create a few lines:
[mysql]
some_setting = somevalue
[client]
some_setting = somevalue
That helps for the "mysql" commandline tool and/or other clients (maybe).
But if you need to make changes to the server mysqld, it needs to be in one of the other files. Again, the minimum is something like
[mysqld]
some_setting = somevalue
Note the mysqld to refer to the server. And remember to restart the service.
Another note: If you see (in an existing config file), !includedir ..., then go to that directory to find any number of further files. You could add your own file, say z.cnf (so it would be picked last) with the two (or more) lines as indicated above.
If you have installed Mysql 8 or Above using the package installer from mysql website, then follow what i did
Create the config file in your home directory vim ~/.my.cnf
Do open System preferences in mac
Then Select the configuration file you created on the option.
The content in this website says.
I had the urgent need to configure some specific stuff in MySQL 5.7 on my developer machine, a MacBook Pro running Mac OS Sierra. Unfortunately, I did not find a my.cnf file that could be customized anywhere?
Internet research showed that MySQL Database Server on Mac OS runs without a my.cnf config file by default, simply started with default values.
Luckily, it is pretty simple to customize the MySQL Server installation by creating and editing a custom my.cnf file like this:
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
Then edit / customize the /etc/my.cnf file as required and restart your MySQL Server.
Or you can refer to this answer
You could try:
$ locate mysql | grep my.cnf
It should reveal the location(s) if it exists.

How to disable strict mode in mysql using MAMP on a mac

I have spent hours trying to figure this out but am seriously stuck. I installed the latest version of mysql today and some things in my website broke. I believe it has to do with strict settings, IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
I am trying to disable strict mode just to get my site working but it seems impossible. I have tried this in terminal but no luck.
sudo vim /etc/mysql/conf.d/disable_mysql_strict_mode.cnf
[mysqld]
sql_mode="IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
I have looked in every etc folder I can find and other various folders but can't see anything that resembles a .cnf file.
I can do it temporarily through phpmyadmin but if I close MAMP or restart my computer I have to do it again as the change isn't permanent.
MAMP Pro
Open MAMP Pro and check your Settings (⌘+,). Make sure Hide Dock Icon is unchecked. If required, uncheck the icon, quit MAMP and restart it.
Note: This is required to see the menu entries for MAMP. You can hide the Dock Icon again later.
Open the main window of MAMP Pro and via the menu go to File > Edit Templates > MySQL > (your version).
This opens a text editor with your MySQL configuration.
In the configuration file look for the line [mysqld] (note the d at the end!).
Right after this line, add a new line with the following text: sql_mode=""
Save the file, close it and restart your MySQL server.
MAMP (free)
By default MAMP free starts the MySQL server without a my.cnf file, i.e. it uses the default configuration which comes with the MySQL build. So you have to create a config file manually:
Quit MAMP (stop the servers)
Run following command in the terminal - it will open the config file inside your text editor app:
touch /Applications/MAMP/conf/my.cnf && open -t /Applications/MAMP/conf/my.cnf
When the file is empty, then add the following content:
[mysqld]
sql_mode=""
(When the file is not empty, then simply add the line sql_mode="" right after the line [mysqld])
Save the config file and close the text editor; restart MAMP and start the servers.
If you are running MySQL 8.x, try the following:
SET PERSIST SQL_MODE = "IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
Trying to find and edit the right my.cnf file can be the wrong strategy. For me the critical information from the MAMP PRO guide was:
You cannot edit my.cnf directly. You
must use the MAMP PRO interface to edit your my.cnf file. In the menu
go to File > Edit Template > MySQL > my.cnf.
For Free Mamp
Go to PhpMyAdmin > Variables Tabs
Find sql mode line and click on edit button
Replace the value with this "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
it works for me
Just to update this for the free version of MAMP 5, I found that MAMP will ignore a my.cnf file placed in the /Applications/MAMP/conf/ directory if the permissions are not set correctly. I ran this command to find that out...
/Applications/MAMP/Library/bin/mysql --verbose --help | grep -A 1 "Default options"
Which told me this.
mysql: [Warning] World-writable config file '/Applications/MAMP/conf/my.cnf' is ignored.
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /Applications/MAMP/conf/my.cnf ~/.my.cnf
Doing
chmod 755 my.cnf
Set it right.

The MySQL57 service on Local Computer started and then stopped

When I try to start my SQL server, a message pops up saying that it starts but then stops. This happened after a restart on my server.
Does anyone know how I can fix this?
Make sure that the data directory has full permissions set for users "Network Service" and Administrator and that you have quotes around the name of the directory if there are spaces in it. Make sure that basedir is set / not commented out.
I tested these things by changing the data directory, which re-caused the error you describe above exactly, then fixed the permissions of the newly created data directory to eliminate the error. I can switch back and forth now my changing which data directory I comment out. (only as a test, otherwise that's kind of nuts).
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini Should be something like this, using Windows 2012 R2 server to test:
# Path to installation directory. All paths are usually resolved relative to
this.
basedir="C:/Program Files/MySQL/MySQL Server 5.7/"
# Path to the database root
# datadir="C:/ProgramData/MySQL/MySQL Server 5.7/Data"
datadir="d:/ProgramData/Data"
Please try the following steps:
run 'cmd' as administrator,
cd to your SQL folder,
run 'mysqld --initialize --user=mysql --console' to reset and
run 'net start mysql' to start the service.
Nothing worked for me except for uninstalling the current 5.7.35 and then installing the 5.7.31. Try downgrading. Might help!
add to config file my.inf on C:\ProgramData\MySQL\MySQL Server 5.7
[mysqld]
tmpdir=C:/temp
and everything will work fine .

How to fix `unknown variable 'sql-mode=ANSI'`?

Using MySQL 5.5.27, in my.cnf I have:
[mysql]
sql_mode=ANSI
Upon starting the mysql console I get:
unknown variable 'sql-mode=TRADITIONAL'
The MySQL doc Server SQL Modes shows that option, so why does it not work?
(If it helps, I am on OSX Lion)
Also, here is a pastebin showing the things another person has tried, with no solution.
sql-mode should be in the [mysqld] section, not in the [mysql] section; if you move sql-mode=ANSI to the [mysqld] section, it should work.
I'm pretty certain the reason it isn't working is because it is an argument for mysqld and not the client. I came up with an alternative way that you could do this instead. Edit your users my.cnf i.e. ~/.my.cnf to be something like this:
[client]
init-command="set sql_mode='TRADITIONAL'"
In config file you should use sql-mode name instead (with dash, not underscore)
http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_sql-mode
And as #cogsmos pointed out, you should put it [mysqld] section

saving MySQL settings

how can i save permanently settings of MySQL ?
i got MySQL from WAMP, and there is no my.cnf file, there is a my.ini file !
how can i set some global variable,
Drive:\wamp\bin\mysql\mysql5.5.8\my.ini
this is the place to save settings.
WAMP uses the my.ini file.
To get to your my.ini file, just click the WAMP tray icon and hover over the 'MySQL' menu, and click 'my.ini'.
Edit your my.ini file and under the [mysqld] section, add this:
setting-name=setting-value , example: event-scheduler=on
restart all services
You do not need to use quotes around either the setting or value.
Global system variables must be specified using the command line or SQL commands (runtime/session) or by configuration file (permanent).
I have had the same question because in WAMP we only have a my.ini file instead of my.conf.
Through a SQL statement, proceeded as follow:
mysql> SET global max_heap_table_size=524288000;
mysql> SET global tmp_table_size=524288000;
but when restarted the server, the query:
select ##global.tmp_table_size, ##global.max_heap_table_size
returned the old values by default.
Then edited my.ini file ading the following statements:
max_heap_table_size=524288000
tmp_table_size=524288000
and the changes were permanent.