#database #mysql #sysadmin #tools
I recently spend a lot of time figuring out why exporting a table from TablePlus was giving me the incorrect output. The setup was that I'm exporting data from a Digital Ocean managed MySQL server and then import this into a local install of MySQL on my mac.
To export, I select one or more table in TablePlus, right-click on them and then choose export to an SQL file.
However, when importing this on my local machine, it failed with:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"migrations" (…
I finally (it took me quite a while) figured out what is causing this: MySQL settings.
If you look at what is exported from the Digital Ocean database, you'll see that the export statements are liked this:
1CREATE TABLE "migrations" ( 2 "id" int unsigned NOT NULL AUTO_INCREMENT, 3 "migration" varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, 4 "batch" int NOT NULL, 5 PRIMARY KEY ("id") 6) ENGINE=InnoDB AUTO_INCREMENT=607 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
What I was expecting was this (note the difference between
1CREATE TABLE `migrations` ( 2 `id` int unsigned NOT NULL AUTO_INCREMENT, 3 `migration` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, 4 `batch` int NOT NULL, 5 PRIMARY KEY (`id`) 6) ENGINE=InnoDB AUTO_INCREMENT=607 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
The difference is caused by the default SQL mode set on Digital Ocean's databases. It has the option
ANSI_QUOTES enabled while the local MySQL (done via homebrew) doesn't have this option. As enabling this setting is considered to be bad practice, I decided to turn it off on the Digital Ocean side.
You can do this by going to the settings tab of your DO database, editing "Global SQL modes" and then removing
ANSI_QUOTES. After that, reconnect with TablePlus and you'll get the expected result.
You can read more about it here.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.