本文章来给大家介绍一下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 = ..... //Vevb.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
新闻热点
疑难解答