mysql5.6设置sql_mode方法详解
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-28 18:38:33 浏览: 评论:0
本文章来给大家介绍一下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 = ..... //phpfensi.com
- # 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
Tags: mysql5 6 sql_mode
相关文章
- ·CentOS6.4安装配置mysql 5.6服务器方法(2014-09-24)
- ·MySQL5.6 Using a password on the command line interface can be insecure(2014-09-24)
- ·mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIM(2014-09-27)
- ·Mysql5.5 InnoDB存储引擎设置(2014-09-28)
- ·MYSQL开启慢查询与mysql5.6开启慢查询出错(2014-10-01)
- ·MySQL5.5默认编码的设置修改方法详解(2014-10-02)
- ·Linux中MySql5手动安装方法详解(2014-10-04)
- ·linux中mysql 5.5二进制文件安装详解(2014-10-04)
- ·mysql5存储过程入门创建,删除,调用详解(2014-10-07)
- ·MySql 5.X创建用户并授权方法(2014-10-08)
- ·mysql5 插入中文乱码问题(2014-10-08)
- ·mysql5.5提示Could not initialize master info structure(2014-10-09)
- ·mysql5 sql-mode 引起的错误解决办法(2014-10-10)
- ·MySQL5的存储过程详细实例(2014-10-13)
- ·php调用mysql5存储过程方法(2014-10-14)
- ·MHA实现mysql5.6主从切换安装配置教程(2014-10-17)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)