[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[],[],null,["# Migrate schema from MySQL overview\n\nThis page shows how to migrate your MySQL schema to Spanner schema.\nWe recommend using the [Spanner migration tool](https://googlecloudplatform.github.io/spanner-migration-tool/ui/schema-conv)\nfor building a Spanner schema from an\nexisting MySQL schema. The tool maps most of the MySQL data types to\nSpanner types, and highlight choices and provide suggestions to\navoid potential migration issues.\n\nData type comparison\n--------------------\n\nMap the following list of MySQL data types to their Spanner\nequivalent:\n\nIn many cases, multiple MySQL types map into a single Spanner\ntype. This is because MySQL has a set of types for the same concept that have\ndifferent length limits, and in Spanner there is one overall type\nthat has a single, relatively large limit.\n\nConsider the following examples:\n\n- MySQL has `TEXT`, `TINYTEXT`, `MEDIUMTEXT`, `LONGTEXT`. In\n Spanner, there is a single type `STRING` with a character-length\n parameter that can be set to any value up to 2,621,440 characters.\n\n- MySQL has `INTEGER`, `INT`, `BIGINT`, `MEDIUMINT`, `SMALLINT` and `TINYINT`.\n Spanner has a single type `INT64` that stores 8-byte signed\n integer values. The main difference is that Spanner's `INT64`\n consumes more storage than `MEDIUMINT`, `SMALLINT` and `TINYINT`.\n In addition, `INT64` doesn't capture the range limitations of `MEDIUMINT`,\n `SMALLINT` and `TINYINT`, although these can be enforced by adding `CHECK`\n constraints.\n\nSpanner doesn't support geospatial types. You can store values\nof these types by encoding them as strings, bytes, or arrays. Any filtering,\noperations, and functions must be performed at the application level.\n\nQueries\n-------\n\nSpanner uses the\n[ANSI 2011 dialect of SQL with extensions](/spanner/docs/query-syntax),\nand has many functions and operators to help translate and aggregate your data.\nAny SQL queries using MySQL-specific dialect, functions, and types need to\nbe converted to be compatible with Spanner.\n\nAlthough Spanner doesn't support structured data as column\ndefinitions, you can use structured data in SQL queries using `ARRAY\u003c\u003e` and\n`STRUCT\u003c\u003e` types. For example, you can write a query that returns all Albums\nfor an artist using an `ARRAY` of `STRUCT`s (taking advantage of the pre-joined\ndata). For more information see the\n[Subqueries](/spanner/docs/query-syntax#subqueries)\nsection of the documentation.\n\nYou can run SQL queries on the Spanner Studio page in\nthe Google Cloud console. In general, queries that\nperform full table scans on large tables are very expensive, and should be used\nsparingly. For more information on optimizing SQL queries, see the\n[SQL best practices](/spanner/docs/sql-best-practices)\ndocumentation.\n\nStored procedures and triggers\n------------------------------\n\nSpanner doesn't support running user code at the\ndatabase level. As part of the schema migration, move the stored procedures and\nbusiness logic triggers that you implemented at the MySQL database-level\ninto your application.\n\nSequences\n---------\n\nSpanner recommends using UUID Version 4 as the default method to\ngenerate primary key values. The\n[`GENERATE_UUID()`](/spanner/docs/reference/standard-sql/utility-functions#generate_uuid)\nfunction returns UUID Version 4 values represented as `STRING` type.\n\nIf you need to generate integer values, Spanner supports\n[bit-reversed positive sequences](/spanner/docs/reference/standard-sql/data-definition-language#create-sequence),\nwhich produce values that distribute evenly across the positive 64-bit number\nspace. You can use these numbers to avoid hot spotting issues.\n\nFor more information, see [primary key default value strategies](/spanner/docs/primary-key-default-value).\n\nWhat's next\n-----------\n\n- [Use SMT to migrate schema from MySQL](/spanner/docs/use-smt-migrate-mysql-schema)."]]