search
HomeDatabaseMysql Tutorialmysql恢复数据数据出现Variable sql_mode cant 解决方法

用mysqldump导出的数据文件,再用source导进去的时候常常有一些报错 ariable sql_mode cant be set to the value of NULL,百度了好几回,终于找到是mysql导出的注释语句问题,导出的文件常常 如下:

01./*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 
02./*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 
03./*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 
04./*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 
05./*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 
06./*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 
07./*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

解决办法

解决方法:删除注释语句后再执行批量SQL语句操作


利用二进制日志恢复报错?Variable 'sql_mode' can't be set to the value of '1344274432'

Server version          5.0.18-log
Protocol version        10
Connection              localhost via TCP/IP

操作系统: windowsXp

mysql为InnoDB存储引擎

数据库为utf


win.ini中配置

[mysql]
default-character-set=utf8

[mysqld]
basedir="c:/MySQL5/"
datadir="c:/MySQL5/Data/"

log-bin="d:/log/log"
binlog-do-db=test
innodb_data_home_dir =
innodb_data_file_path=e:/MySQL Datafiles/ibdata1:10M;e:/MySQL Datafiles/ibdata2:1M:autoextend

innodb_log_group_home_dir="d:/log/binlog/"
default-character-set=utf8
default-storage-engine=INNODB

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

...............


恢复冷备份后,执行日志恢复报错
C:\mysqlbinlog d:/log/log.000002|mysql -uroot -pa

ERROR 1231 (42000) at line 10: Variable 'sql_mode' can't be set to the value of
'1344274432'

------------------------

显示日志如下:
C:\mysqlbinlog d:/log/log.000002

/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
# at 4
#070423  1:10:40 server id 1  end_log_pos 98    Start: binlog v 4, server v 5.0.
18-log created 070423  1:10:40
# at 98
#070423  1:10:46 server id 1  end_log_pos 93    Query   thread_id=9     exec_tim
e=0     error_code=0
use iservice;
SET TIMESTAMP=1177261846;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.uniq
ue_checks=1;
SET @@session.sql_mode=1344274432;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@sessio
n.collation_server=33;
insert into test values(3);
# at 191
#070423  1:10:46 server id 1  end_log_pos 218   Xid = 27
COMMIT;
# at 218
#070423  1:11:02 server id 1  end_log_pos 237   Stop
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;


解决方法

mysqlbinlog:用于处理二进制日志文件的实用工具
服务器生成的二进制日志文件写成二进制格式。要想检查这些文本格式的文件,应使用mysqlbinlog实用工具。

应这样调用mysqlbinlog:

shell> mysqlbinlog [options] log-files...
例如,要想显示二进制日志binlog.000003的内容,使用下面的命令:

shell> mysqlbinlog binlog.0000003
输出包括在binlog.000003中包含的所有语句,以及其它信息例如每个语句花费的时间、客户发出的线程ID、发出线程时的时间戳等等。

通常情况,可以使用mysqlbinlog直接读取二进制日志文件并将它们用于本地MySQL服务器。也可以使用--read-from-remote-server选项从远程服务器读取二进制日志。

当读取远程二进制日志时,可以通过连接参数选项来指示如何连接服务器,但它们经常被忽略掉,除非你还指定了--read-from-remote-server选项。这些选项是--host、--password、--port、--protocol、--socket和--user。

还可以使用mysqlbinlog来读取在复制过程中从服务器所写的中继日志文件。中继日志格式与二进制日志文件相同。


mysqlbinlog支持下面的选项:

·         ---help,-?

显示帮助消息并退出。

·         ---database=db_name,-d db_name

只列出该数据库的条目(只用本地日志)。

·         --force-read,-f

使用该选项,如果mysqlbinlog读它不能识别的二进制日志事件,它会打印警告,忽略该事件并继续。没有该选项,如果mysqlbinlog读到此类事件则停止。

·         --hexdump,-H

在注释中显示日志的十六进制转储。该输出可以帮助复制过程中的调试。在MySQL 5.1.2中添加了该选项。

·         --host=host_name,-h host_name

获取给定主机上的MySQL服务器的二进制日志。

·         --local-load=path,-l pat

为指定目录中的LOAD DATA INFILE预处理本地临时文件。

·         --offset=N,-o N

跳过前N个条目。

·         --password[=password],-p[password]

当连接服务器时使用的密码。如果使用短选项形式(-p),选项和 密码之间不能有空格。如果在命令行中--password或-p选项后面没有 密码值,则提示输入一个密码。

·         --port=port_num,-P port_num

用于连接远程服务器的TCP/IP端口号。

·         --position=N,-j N

不赞成使用,应使用--start-position。

·         --protocol={TCP | SOCKET | PIPE | -position

使用的连接协议。

·         --read-from-remote-server,-R

从MySQL服务器读二进制日志。如果未给出该选项,任何连接参数选项将被忽略。这些选项是--host、--password、--port、--protocol、--socket和--user。

·         --result-file=name, -r name

将输出指向给定的文件。

·         --short-form,-s

只显示日志中包含的语句,不显示其它信息。

·         --socket=path,-S path

用于连接的套接字文件。

·         --start-datetime=datetime

从二进制日志中第1个日期时间等于或晚于datetime参量的事件开始读取。datetime值相对于运行mysqlbinlog的机器上的本地时区。该值格式应符合DATETIME或TIMESTAMP数据类型。例如:

shell> mysqlbinlog --start-datetime="2004-12-25 11:25:56" binlog.000003
该选项可以帮助点对点恢复。

·         --stop-datetime=datetime

从二进制日志中第1个日期时间等于或晚于datetime参量的事件起停止读。关于datetime值的描述参见--start-datetime选项。该选项可以帮助及时恢复。

·         --start-position=N

从二进制日志中第1个位置等于N参量时的事件开始读。

·         --stop-position=N

从二进制日志中第1个位置等于和大于N参量时的事件起停止读。

·         --to-last-logs,-t

在MySQL服务器中请求的二进制日志的结尾处不停止,而是继续打印直到最后一个二进制日志的结尾。如果将输出发送给同一台MySQL服务器,会导致无限循环。该选项要求--read-from-remote-server。

·         --disable-logs-bin,-D

禁用二进制日志。如果使用--to-last-logs选项将输出发送给同一台MySQL服务器,可以避免无限循环。该选项在崩溃恢复时也很有用,可以避免复制已经记录的语句。注释:该选项要求有SUPER权限。

·         --user=user_name,-u user_name

连接远程服务器时使用的MySQL用户名。

·         --version,-V

显示版本信息并退出。

还可以使用--var_name=value选项设置下面的变量:

·         open_files_limit

指定要保留的打开的文件描述符的数量。

可以将mysqlbinlog的输出传到mysql客户端以执行包含在二进制日志中的语句。如果你有一个旧的备份,该选项在崩溃恢复时也很有用

shell> mysqlbinlog hostname-bin.000001 | mysql
或:

shell> mysqlbinlog hostname-bin.[0-9]* | mysql
如果你需要先修改含语句的日志,还可以将mysqlbinlog的输出重新指向一个文本文件。(例如,想删除由于某种原因而不想执行的语句)。编辑好文件后,将它输入到mysql程序并执行它包含的语句。

mysqlbinlog有一个--position选项,只打印那些在二进制日志中的偏移量大于或等于某个给定位置的语句(给出的位置必须匹配一个事件的开始)。它还有在看见给定日期和时间的事件后停止或启动的选项。这样可以使用--stop-datetime选项进行点对点恢复(例如,能够说“将数据库前滚动到今天10:30 AM的位置”)。

如果MySQL服务器上有多个要执行的二进制日志,安全的方法是在一个连接中处理它们。下面是一个说明什么是不安全的例子:

 代码如下 复制代码
shell> mysqlbinlog hostname-bin.000001 | mysql # DANGER!!
shell> mysqlbinlog hostname-bin.000002 | mysql # DANGER!!

使用与服务器的不同连接来处理二进制日志时,如果第1个日志文件包含一个CREATE TEMPORARY TABLE语句,第2个日志包含一个使用该临时表的语句,则会造成问题。当第1个mysql进程结束时,服务器撤销临时表。当第2个mysql进程想使用该表时,服务器报告 “不知道该表”。

要想避免此类问题,使用一个连接来执行想要处理的所有二进制日志中的内容。下面提供了一种方法:

 代码如下 复制代码
shell> mysqlbinlog hostname-bin.000001 hostname-bin.000002 | mysql

另一个方法是:

 代码如下 复制代码
shell> mysqlbinlog hostname-bin.000001 >  /tmp/statements.sql
shell> mysqlbinlog hostname-bin.000002 >> /tmp/statements.sql
shell> mysql -e "source /tmp/statements.sql"

mysqlbinlog产生的输出可以不需要原数据文件即可重新生成一个LOAD DATA INFILE操作。mysqlbinlog将数据复制到一个临时文件并写一个引用该文件的LOAD DATA LOCAL INFILE语句。由系统确定写入这些文件的目录的默认位置。要想显式指定一个目录,使用--local-load选项。

因为mysqlbinlog可以将LOAD DATA INFILE语句转换为LOAD DATA LOCAL INFILE语句(也就是说,它添加了LOCAL),用于处理语句的客户端和服务器必须配置为允许LOCAL操作。参见5.6.4节,“LOAD DATA LOCAL安全问题”。

警告:为LOAD DATA LOCAL语句创建的临时文件不会自动删除,因为在实际执行完那些语句前需要它们。不再需要语句日志后应自己删除临时文件。文件位于临时文件目录中,文件名类似original_file_name-#-#。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL's Place: Databases and ProgrammingMySQL's Place: Databases and ProgrammingApr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL: From Small Businesses to Large EnterprisesMySQL: From Small Businesses to Large EnterprisesApr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?Apr 13, 2025 am 12:16 AM

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL: Not a Programming Language, But...MySQL: Not a Programming Language, But...Apr 13, 2025 am 12:03 AM

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL: An Introduction to the World's Most Popular DatabaseMySQL: An Introduction to the World's Most Popular DatabaseApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

The Importance of MySQL: Data Storage and ManagementThe Importance of MySQL: Data Storage and ManagementApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

Why Use MySQL? Benefits and AdvantagesWhy Use MySQL? Benefits and AdvantagesApr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Apr 12, 2025 am 12:16 AM

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools