Quantcast
Channel: DDL – Cloud Data Architect
Viewing all articles
Browse latest Browse all 275

Importing Data from SQL Server to MariaDB

$
0
0

Feed: MariaDB Knowledge Base Article Feed.
Author: .

There are several ways to move data from SQL Server to MariaDB. There are also some caveats.

Moving Data Definition from SQL Server to MariaDB

To copy an SQL Server data structures to MariaDB, one has to:

  1. Generate a file containing the SQL commands to recreate the database.
  2. Modify the syntax so that it works in MariaDB.
  3. Run the file in MariaDB.

Variables That Affect DDL Statements

DDL statements are affected by some server system variables.

sql_mode determines the behavior of some SQL statements and expressions, including how strict error checking is, and some details regarding the syntax. Objects like stored procedures, stored functions triggers and views, are always executed with the sql_mode that was in effect during their creation. sql_mode='MSSQL' can be used to have MariaDB behaving as close to SQL Server as possible.

innodb_strict_mode enables the so-called InnoDB strict mode. Normally some errors in the CREATE TABLE options are ignored. When InnoDB strict mode is enabled, the creation of InnoDB tables will fail with an error when certain mistakes are made.

updatable_views_with_limit determines whether view updates can be made with an UPDATE or DELETE statement with a LIMIT clause if the view does not contain all primary or not null unique key columns from the underlying table.

Dumps and sys.sql_modules

The SQL Server Management Studio allows to create an SQL script to recreate a database – something that MariaDB users refer to as a dump. Similarly, the sp_helptext() procedure returns the SQL statement to recreate a certain object, and those definitions are also present in the sql_modules table (definition column), in the sys schema. Therefore, it is easy to create a text files containing the SQL statements to recreate a database or part of it.

Remember however that MariaDB does not support schemas. An SQL Server schema is approximately a MariaDB database.

To execute a dump, we can pass the file to mysql, the MariaDB command-line client.

Provided that a dump file contains syntax that is valid with MariaDB, it can be executed in this way:

mysql --show-warnings < dump.sql

--show-warnings tells MariaDB to output any warnings produced by the statements contained in the dump. Without this option, warnings will not appear on screen. Warnings don't stop the dump execution.

Errors will appear on screen. Errors will stop the dump execution, unless the --force option (or just -f) is specified.

For other mysql options, see mysql Command-line Client Options.

Another way to achieve the same purpose is to start the mysql client in interactive mode first, and then run the source command. For example:

root@d5a54a082d1b:/# mysql -uroot -psecret
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 22
Server version: 10.4.7-MariaDB-1:10.4.7+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> W
Show warnings enabled.
MariaDB [(none)]> source dump.sql

In this case, to show warnings we used the W command, where "w" is uppercase. To hide warnings (which is the default), we can use w (lowercase).

For other mysql commands, see mysql Commands.

Syntax Notes

Moving Data from SQL Server to MariaDB

Importing a CSV file

CONNECT


Viewing all articles
Browse latest Browse all 275

Trending Articles