# Migrating from MySQL

How to map existing data and concepts from PostgreSQL to SurrealDB

This page details some MySQL data types and their SurrealQL equivalents, followed by links to the [Surreal Sync](https://github.com/surrealdb/surreal-sync/) tool which allows data from MySQL to be automatically imported to SurrealDB.

## Data types

The following chart shows MySQL data types along with the equivalent or near-equivalent [SurrealQL data type](/docs/reference/query-language/language-primitives/data-types.md) for each.

|   MySQL Data Type   | Wire Protocol Type |               SQL Representation                | SurrealDB Mapping |                     Notes                      |
| ------------------- | ------------------ | ----------------------------------------------- | ----------------- | ---------------------------------------------- |
| **BOOLEAN/BOOL**    | Tiny               | `0`/`1`                                         | `bool`            | 0=false, 1=true conversion                     |
| **TINYINT**         | Tiny               | `-128` to `127`                                 | `int`             | Converted to 64-bit integer                    |
| **SMALLINT**        | Short              | `-32768` to `32767`                             | `int`             | Converted to 64-bit integer                    |
| **MEDIUMINT**       | Int24              | `-8388608` to `8388607`                         | `int`             | Converted to 64-bit integer                    |
| **INT/INTEGER**     | Long               | `-2147483648` to `2147483647`                   | `int`             | Converted to 64-bit integer                    |
| **BIGINT**          | LongLong           | `-9223372036854775808` to `9223372036854775807` | `int`             | Direct conversion                              |
| **FLOAT**           | Float              | `3.14`                                          | `float` (f64)     | Converted to double precision                  |
| **DOUBLE**          | Double             | `3.141592653589793`                             | `float` (f64)     | Direct conversion                              |
| **DECIMAL/NUMERIC** | NewDecimal         | `123.45`                                        | `number`          | Converted to SurrealDB Number with precision   |
| **CHAR(n)**         | String             | `'text'`                                        | `string`          | Fixed-length, padding removed                  |
| **VARCHAR(n)**      | VarString          | `'text'`                                        | `string`          | Variable-length string                         |
| **TEXT**            | Blob               | `'long text'`                                   | `string`          | Text blob as string                            |
| **TINYTEXT**        | TinyBlob           | `'short text'`                                  | `string`          | Small text as string                           |
| **MEDIUMTEXT**      | MediumBlob         | `'medium text'`                                 | `string`          | Medium text as string                          |
| **LONGTEXT**        | LongBlob           | `'very long text'`                              | `string`          | Large text as string                           |
| **BINARY(n)**       | String             | `0x48656c6c6f`                                  | `bytes`           | Fixed-length binary data                       |
| **VARBINARY(n)**    | VarString          | `0x48656c6c6f`                                  | `bytes`           | Variable-length binary data                    |
| **BLOB**            | Blob               | `0x48656c6c6f`                                  | `bytes`           | Binary large object                            |
| **TINYBLOB**        | TinyBlob           | `0x48656c6c6f`                                  | `bytes`           | Small binary data                              |
| **MEDIUMBLOB**      | MediumBlob         | `0x48656c6c6f`                                  | `bytes`           | Medium binary data                             |
| **LONGBLOB**        | LongBlob           | `0x48656c6c6f`                                  | `bytes`           | Large binary data                              |
| **DATE**            | Date               | `'2024-01-15'`                                  | `datetime`        | Converted to datetime at midnight UTC          |
| **TIME**            | Time               | `'14:30:00'`                                    | `string`          | Time format as string (HH:MM:SS.microseconds)  |
| **DATETIME**        | DateTime           | `'2024-01-15 14:30:00'`                         | `datetime`        | Converted to UTC datetime                      |
| **TIMESTAMP**       | Timestamp          | `'2024-01-15 14:30:00'`                         | `datetime`        | Timezone-aware, converted to UTC               |
| **YEAR**            | Year               | `2024`                                          | `int`             | Year as integer                                |
| **JSON**            | Json               | `'{"key": "value"}'`                            | `object`          | Parsed and converted recursively               |
| **GEOMETRY**        | Geometry           | `ST_GeomFromText('POINT(1 2)')`                 | `object`          | Converted to geometric object with coordinates |
| **POINT**           | Geometry           | `POINT(1.5, 2.5)`                               | `object`          | Converted to `{"x": 1.5, "y": 2.5}` object     |
| **ENUM**            | Enum               | `'option1'`                                     | `string`          | Enum value as string, constraints lost         |
| **SET**             | Set                | `'value1,value2'`                               | `array`           | Converted to array of strings                  |
| **BIT(n)**          | Bit                | `b'1010'`                                       | `string`          | Bit string as binary string representation     |

## Importing from MySQL using Surreal Sync

Surreal Sync can be used to exports MySQL tables to SurrealDB.

It supports inconsistent full syncs and consistent incremental syncs, and together provides ability to reproduce consistent snapshots from the source MySQL tables onto the target SurrealDB tables.

For more on how to import data from MySQL to SurrealDB, please see the following pages in the Surreal Sync repo.

* [Surreal Sync for MySQL](https://github.com/surrealdb/surreal-sync/blob/main/docs/mysql.md)
* [MySQL Data Types Support in Surreal Sync](https://github.com/surrealdb/surreal-sync/blob/main/docs/mysql-data-types.md)
