百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> mysql5.6设置sql_mode方法详解
分享文章到:

mysql5.6设置sql_mode方法详解

发布时间:01/15 来源: 浏览: 关键词:
本文章来给大家介绍一下mysql5.6设置sql_mode方法详解,希望此方法对各位同学会有所帮助哦。

首先登录mysql终端

 代码如下

mysql -u xxx -pxxxxx

查看当前mysql的sql_mode

 代码如下
mysql> select @@sql_mode;
+--------------------------------------------+
| @@sql_mode                                 |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |

+--------------------------------------------+


将mysql的sql_mode 设为 MYSQL40 也就是 NO_FIELD_OPTIONS,HIGH_NOT_PRECEDENCE

 代码如下


mysql> SET sql_mode=`NO_FIELD_OPTIONS,HIGH_NOT_PRECEDENCE`;
Query OK, 0 rows affected (0.00 sec)


mysql> select @@sql_mode;
+--------------------------------------+
| @@sql_mode                           |
+--------------------------------------+
| NO_FIELD_OPTIONS,HIGH_NOT_PRECEDENCE |
+--------------------------------------+
1 row in set (0.00 sec)


需要注意的是 上面的修改  sql_mode 只是会话级别的,只影响当前会话,退出终端后既失效


下面这个才是设置全局级别的变量,适用于所有会话,但仅限于本次mysql进程,下次重启还要重新设置

 代码如下
set global sql_mode=`NO_FIELD_OPTIONS,HIGH_NOT_PRECEDENCE`

详细用法

 代码如下

SET [GLOBAL|SESSION] sql_mode='modes'

每次启动自动设置sql_mode可以在启动脚本里面加上

 代码如下


mysql --sql-mode="NO_FIELD_OPTIONS,HIGH_NOT_PRECEDENCE"


sql_mode默认设置问题 .


编译并配置完MySQL5.6版本,导入之前在MySQL5.5中正常运行的数据库却发生错误,原来从MySQL5.6版本开始,在执行mysql_install_db命令时(该命令一般在编译完mysql后运行并对数据库进行初始配置)会将默认的一个my.cnf文件写入到安装路径中(CentOS下默认安装路径为/usr/local/mysql/),其包含的信息如下:

 代码如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# 作者按: 见这里的配置
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有5人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板