How to get rid of STRICT SQL mode in MySQL

后端 未结 7 747
日久生厌
日久生厌 2020-12-15 04:59

This is a follow up to this question MYSQL incorrect DATETIME format

How to get rid of STRICT_TRANS_TABLES once and for all?

mysql --help report

相关标签:
7条回答
  • 2020-12-15 05:12

    So in the end I removed the MySQL Server I got from the mysql.com, reinstalled it via Homebrew and had to edit

    /usr/local/Cellar/mysql/5.6.xx/my.cnf
    

    Where I could comment out the darned STRICT_TRANS_TABLES.

    However this doesn't explain why the default config overrides the one from /etc/my.cnf, but I spent too much time on this already as it is. And by the way I am still not sure what to do with the mysql.com provided distribution.

    0 讨论(0)
  • 2020-12-15 05:13

    According to MySQL Strict Mode on OS X the problematic setting is actually at /usr/local/mysql/my.cnf and can be commented out to stop this behavior.

    0 讨论(0)
  • 2020-12-15 05:15

    On Mac OS X El Capitan i created a file .my.cnf in the user home dir and set the settings for mysql under [mysqld] and then restarted mysql. Worked fine!

    0 讨论(0)
  • 2020-12-15 05:18

    I tried every answer I could find on this issue using MySQL 5.7 on Mac OS 10.12 and ultimately got strict mode turned off not because of the location of my.cnf, which can presumably be in any of the places that MySQL says it checks, but thanks to a UNIX permissions issue.

    I used MySQL Workbench 6.2.3.12313 to create my.cnf initially. This caused two possible problems: first, it set the option to "sql-mode" instead of "sql_mode", and it made the file (located in /etc) readable and writable only for root. MySQL does not run as root when you install it the way I did, from the binary package on the MySQL web site--it runs as _mysql. So the _mysql user needs to be able to read /etc/my.cnf, or wherever you put it. In order for that to work, you need to run:

    sudo chmod o+r /etc/my.cnf
    

    and for good measure you may also want to run:

    sudo chmod g+r /etc/my.cnf
    

    Then make sure to restart MySQL. (I have found that this works best through the System Preferences MySQL panel on Mac OS; using the command line is kind of messy and MySQL Workbench's functionality simply doesn't work.) So long as you have an sql_mode setting in my.cnf that does not involve strict mode, strict mode should be off.

    0 讨论(0)
  • 2020-12-15 05:22

    Now you can`t set sql_mode to empty string, actual query is:

    SET @@GLOBAL.sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    

    MySQL 5.7.16

    0 讨论(0)
  • 2020-12-15 05:24

    This problem scuppered me for a while as well. None of the answers so far addressed the original problem but I believe mine does so I'll post it in case it helps anyone else.

    I have MySQL (from mysql.com) Community Edition 5.7.10 installed on OS X 10.10.3

    In the end I created a /etc/mysql/my.cnf with the following contents:-

    [mysqld]
    
    sql_mode=NO_ENGINE_SUBSTITUTION
    

    After restarting the server a SHOW VARIABLES LIKE 'sql_mode'; gave me:-

    +---------------+------------------------+
    | Variable_name | Value                  |
    +---------------+------------------------+
    | sql_mode      | NO_ENGINE_SUBSTITUTION |
    +---------------+------------------------+
    1 row in set (0.00 sec)
    

    Finally, no strict mode!

    0 讨论(0)
提交回复
热议问题