Import and export of SQL scripts
Moving whole databases in and out of Raft DB as mysqldump files and as SQL Server (SSMS) scripts with the program raftdb-dump, what is checked against MySQL and MariaDB, and what is refused.
raftdb-dump reads and writes the script files that MySQL, MariaDB and SQL Server tools write, so a database can come to Raft DB from them and go back. It runs the script through the MySQL or SQL Server front-end of Raft DB: a script Raft DB takes is a script the front-end understands.
raftdb-dump import --dialect mysql --data /var/lib/raftdb-import --database shop shop-dump.sql
raftdb-dump import --dialect mssql --raftdb 127.0.0.1:7480 --raftdb-user admin --raftdb-password PW --database Sales Sales.sql
raftdb-dump export --dialect mysql --data /var/lib/raftdb-import --database shop shop-out.sql
raftdb-dump export --dialect mssql --data /var/lib/raftdb-import --database Sales Sales-out.sql--data DIR runs a Raft DB server inside the program on that data folder, --embed raftdb.conf does the same from a configuration file and --raftdb HOST:PORT uses a server that is already running. --dialect is mysql, mariadb or mssql.
Import#
The file is read line by line (never as a whole: a 30 MB dump is no problem) and cut into statements: for MySQL at the delimiter outside strings and comments, with DELIMITER ;; for routines and /*!40101 ... */ comments as code; for SQL Server into the batches between GO lines (GO 5 repeats), and a data script of one huge batch without GO is cut between its INSERTs. The encodings are UTF-8, UTF-8 with a byte-order mark, UTF-16 (SSMS's default) and Windows-1252, recognised from the file; --encoding forces one. The bytes of a _binary '...' value in a mysqldump file arrive unchanged.
The report counts the statements sent, those that worked and those the server refused, and groups the refusals by error number and message with the file line and the statement (without row data) of the first of each. --log FILE lists every refusal with its line. The default is to go on after an error; --stop-on-error stops at the first one. The exit code is 0 when nothing was refused.
Export#
The MySQL file is what mysqldump writes: the header with the character set and the checks switched off, DROP TABLE IF EXISTS and CREATE TABLE, LOCK TABLES and extended INSERTs, then views, triggers, routines and events. The SQL Server file is what SSMS "Generate Scripts" writes for schema and data: GO batches, [dbo].[t] names, IDENTITY(seed,step), SET IDENTITY_INSERT, one INSERT per row, then defaults, indexes, checks and foreign keys, then views, functions, procedures and triggers. The DEFINER of MySQL objects is left out so that the loading user becomes the definer.
What is checked#
Against the real MySQL 9.7, with scratch databases only: an export from Raft DB loads in MySQL without an error and every table has the same rows (a checksum of each column and of the whole row set); a dump written by the real mysqldump imports into Raft DB with the same result; and import, export, import again gives the same tables. Design reasons and the numbers are in decision D138.
What is different or refused#
SQL Server allows one NULL in a UNIQUE key and Raft DB's front-end allows many (so such data cannot be loaded back into MySQL); INCLUDE columns of an index, DESC keys, filtered indexes other than IS NOT NULL, partitions, file groups and the file options of CREATE DATABASE are read and ignored; LOAD DATA LOCAL INFILE inside a MySQL script is refused; A trigger of SQL Server is listed by the catalog in schema dbo whatever its schema.