Ben Zittlau
Ben Zittlau

Reputation: 2485

What do the statements at the start of a MysqlDump do?

Looking at the output of a mysqldump I see the following at the top.

Similarly scattered throughout I see various statements in /*! */ blocks. My guess would be that these are probably conditionally executing based on version, but unfortunately with google stripping out symbols it's been difficult to confirm this.

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

Here's another reference to these statements in the MySQL manual (that also doesn't explain what they do).

https://dev.mysql.com/doc/refman/5.5/en/mysqldump.html#option_mysqldump_disable-keys

Upvotes: 3

Views: 770

Answers (1)

chrislondon
chrislondon

Reputation: 12031

You'll notice before it creates tables and such you will have a line like this:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

And then after all those things you'll have a line like this:

/*!40101 SET @CHARACTER_SET_CLIENT=@@OLD_CHARACTER_SET_CLIENT */;

What these lines do is save the database's current settings, change them to what the import file needs, runs the queries, and then sets the database's settings back to the way they were.

Upvotes: 1

Related Questions