Port a database from MySQL to MemSQL

Source: Internet
Author: User
Tags unsupported memsql
Because MemSQL is fully compatible with MySQL, It is very straightforward to migrate data from MySQL to MemSQL. You can use standard MySQL tools for migration. This example is false.

Because MemSQL is fully compatible with MySQL, It is very straightforward to migrate data from MySQL to MemSQL. You can use standard MySQL tools for migration. This example is false.

Because MemSQL is fully compatible with MySQL, It is very straightforward to migrate data from MySQL to MemSQL. You can use standard MySQL tools for migration.

In this example, we assume that both your MySQL and MemSQL run on the same machine, MySQL runs on port 3306, and MemSQL runs on port 3307, and both of them can be accessed through the root account without a password.

Use mysqldump

MysqldumpIt is one of the most common data backup tools for MySQL clients. It generates SQL statements for creating tables and inserting data in columns. Therefore, it is most convenient to restore a database.

When you are sure you want to migrate data to MemSQL, there are several considerations:

  • Most MySQL storage engines use B-tree to store indexes, while MemSQL uses a one-way unlocked skip List or lockless hash table. Selecting the correct index data structure will significantly improve the application performance. Hash Tables are mainly suitable for key-value searches, while skip lists are especially suitable for scanning and sorting complex ranges (order ). Therefore, before performing the migration, You need to review your table definition and determine whether MemSQL exclusive optimization can be used. The default BTREE symbol is converted to the list of skips in ascending order. If you want to perform a two-way range scan on a column, you can consider adding both ascending and descending indexes. For more information about the MemSQL indexes, see indexes.
  • Because of code generation, MemSQL loads the database structure more slowly than MySQL for the first time. Because MemSQL loads the table structure for the first time, it generates and compiles code to implement the table architecture, including memory allocation, insertion, deletion, and iteration methods. Once the table is compiled, MemSQL directly uses the compiled code during the entire operation. The INSERT statement generated by mysqldump will also be compiled once.
  • MysqldumpSome SQL statements not supported by MemSQL are generated. For example, UNIQUE_CHECKS is not supported. To better support mysqldump, MemSQL only generates warnings for these unsupported statements. You can adjust them.Warn_levelVariable to control the error level. For details, see Unsupported Features. Some create table statements may be completely blocked for execution. If you encounter this problem, you can only manually modify the definition SQL of the TABLE.
  • If the machine running MemSQL does not have enough memory to load data, the server will report the out-of-memory error message for executing the INSERT statement, in this case, you can only install more memory. If you copy the existing memsqlbin directory to a new machine, MemSQL will continue to use compiled table definitions and INSERT statements. If you are using the MemSQL development edition and exceed the 10 Gb limit, you can refer to memsql.com/next to learn how to upgrade.
  • We recommend that you separate the database structure definition and data to store independent files, so that you can adjust the table structure as needed. You can use the following command to export the database structure and data files respectively:

    $Mysqldump-h 127.0.0.1-u root-B[Database name]-- No-data> schema. SQL$Mysqldump-h 127.0.0.1-u root-B[Database name]-- No-create-info> data. SQL

    Then import the data using the following method:

    $Mysql-h 127.0.0.1-u root-P 3307 <schema. SQL$Mysql-h 127.0.0.1-u root-P 3307 <data. SQL

    When running these steps, you can observe memsql_tracelog (also output to stderr) to view unsupported features ignored during execution. Once the import is complete, you can connect to MemSQL and query the results.

    Convert your application

    It is very easy for applications to support MemSQL. You only need to change the connection configuration.

    Note:

    If you want to connect to MemSQL on the local machine, you should use 127.0.0.1 instead of localhost. Most MySQL clients can parse localhost and use the MySQL socket file for connection, ignoring port settings. For details, see this page.

    Once you start running the program, you can monitor memsql_tracelog. Some unsupported SQL syntax will be displayed here. More SQL Statements for MemSQL

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.