{"baslik":"Mysql Strict Mod Kapatma","icerik":"
\r\n\tmysql strict modu bazen default value ile gelen veri uyu\u00femay\u00fdnca ve not null tan\u00fdmlanm\u00fd\u00fesa vb. sorun olabiliyor ve kayd\u00fd alm\u00fdyor.<\/p>\r\n
\r\n\tkendim için buldu\u00f0um çözümü kay\u00fdt etmek istedim.<\/p>\r\n
\r\n\tSELECT<\/span> <\/span>@@GLOBAL.sql_mode<\/span>;<\/span> <\/span>SELECT<\/span> <\/span>@@SESSION.sql_mode<\/span>;<\/span><\/p>\r\n \r\n\t <\/p>\r\n \r\n\t <\/p>\r\n \r\n\tReading Time: <\/span>3<\/span> minutes<\/span><\/span>MySQL’s, and MariaDB’s, strict mode controls how invalid or missing values in data changing queries are handled; this includes INSERT, UPDATE, and CREATE TABLE statements. With MySQL strict mode enabled, which is the default state, invalid or missing data may cause warnings or errors when attempting to process the query. When strict mode is disabled the same query would have its invalid, or missing, values adjusted and would produce a simple warning. This may seem like the preferred result, however with strict mode disabled certain actions may cause unexpected results; for instance, when the value being inserted exceeds the maximum character limit it will be truncated to fit the limit.<\/span> There are various reasons why MySQL’s strict mode may need to be disabled, however the most common is when a server is running WHMCS — this is a requirement of that tool.<\/span><\/p>\r\n \r\n\tWhenever modifying files on a server it’s always best practice to take some form of a backup beforehand. This ensures you have a way to revert changes if something goes awry; it’s also beneficial because it helps track when and what changes were made. While logged into SSH with the root user, do the following:<\/span> \r\n\tDepending on the server and the current configurations you may need to edit one, or both, of the following files on the server. Generally, the relevant configuration lines are only in one of them, however, it could be in either one without causing issues; so generally it’s best to check both. To edit the files, you will open the file with your favorite command line editor. In this example, we use ‘vim’.<\/span> \r\n\tWithin each file above you will be looking for a line with the following content:<\/span> \r\n\tFinally, to make these changes effective you will need to restart the MySQL service as it will only read the configuration files when it initially loads up. In order to force MySQL to use the new configuration files you will do the following: For CentOS 7 servers:<\/span>SET<\/span> GLOBAL<\/span> sql_mode = 'NO_ENGINE_SUBSTITUTION'<\/span>;\r\nSET<\/span> SESSION<\/span> sql_mode = 'NO_ENGINE_SUBSTITUTION'<\/span>;\r\n\r\nDosya ile: \/etc\/my.cnf dosyas\u00fdna sql_mode="" <\/code>ekleyerek<\/span><\/pre>
\r\n\tPre-Flight Check<\/h2>\r\n
\r\n\t
\r\n\tStep #1: Make Backups, Always!<\/h2>\r\n
cp -a \/usr\/my.cnf{,.strict.bak} cp -a \/etc\/my.cnf{,.strict.bak}<\/code><\/p>\r\n
\r\n\tStep #2: Disable MySQL Strict Mode<\/h2>\r\n
vim \/usr\/my.cnf vim \/etc\/my.cnf<\/code><\/p>\r\n
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES<\/code>If you find a line similar to the above that is setting the `sql_mode` variable then you will need to replace it with the following line to disable MySQL strict mode.<\/span>
sql_mode=""<\/code>Once this adjustment has been made, or you’ve confirmed the file does not need to be adjusted you will then save and close the file.<\/span><\/p>\r\n
\r\n\tStep #3: Restart the MySQL Service<\/h2>\r\n
systemctl restart mysql<\/code>For CentOS 6 and prior:<\/span>
\/etc\/init.d\/mysql restart<\/code>After issuing this command on the server the MySQL service will be restarted and will load the changes made. If all the directions were followed and completed, then MySQL strict mode should now be disabled. To verify that the process was completed properly you can run the following:<\/span>
mysql -e "SELECT @@sql_mode;"<\/code>The output may look similar to the following:<\/span>
+--------------------------------------------+ | @@sql_mode +--------------------------------------------+ | NO_AUTO_CREATE_USER +--------------------------------------------+<\/code>If you have any questions or are not comfortable making these changes yourself, please feel free to contact <\/span>Heroic Support®<\/a>.
\r\n\thttps:\/\/stackoverflow.com\/questions\/15438840\/mysql-error-1364-field-doesnt-have-a-default-values<\/a>
\r\n\t<\/span><\/p>\r\n"}