Stay organized with collections
Save and categorize content based on your preferences.
This document describes how to install a predefined library of MySQL functions
in a Spanner database. You can add these functions to your
database using the Google Cloud console or the Google Cloud CLI.
Installing these MySQL functions extends Spanner's capabilities,
allowing you to perform operations that are common in MySQL environments
directly within Spanner.
For more information about the MySQL functions that Spanner
supports, see MySQL functions.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Install MySQL user-defined functions\n\nThis document describes how to install a predefined library of MySQL functions\nin a Spanner database. You can add these functions to your\ndatabase using the Google Cloud console or the Google Cloud CLI.\n\nInstalling these MySQL functions extends Spanner's capabilities,\nallowing you to perform operations that are common in MySQL environments\ndirectly within Spanner.\n\nFor more information about the MySQL functions that Spanner\nsupports, see [MySQL functions](/spanner/docs/reference/mysql/user_defined_functions_all).\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to install the MySQL functions,\n\nask your administrator to grant you the\n\n\n[Cloud Spanner Database Admin](/iam/docs/roles-permissions/spanner#spanner.databaseAdmin) (`roles/spanner.databaseAdmin`)\nIAM role on your project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nInstall the MySQL user-defined functions\n----------------------------------------\n\nYou can install the MySQL user-defined functions in a Spanner\ndatabase in the following ways: \n\n### Google Cloud console\n\n1. In the Google Cloud console, go to the Spanner **Instances** page.\n\n [Go to the Instances page](https://console.cloud.google.com/spanner/instances)\n2. Click the instance containing the database.\n\n3. Click the database.\n\n4. Click the **Write DDL** button to open Spanner Studio.\n\n5. Copy the entire content of the DDL file in the [`mysql_udfs.sql`](https://github.com/googleapis/spanner-sql-udf/blob/main/mysql/mysql_udfs.sql)\n file.\n\n6. In a SQL editor tab, paste the copied content from the DDL file,\n\n7. Click **Run**.\n\n### gcloud\n\nYou can use the [`gcloud spanner database ddl update`](/sdk/gcloud/reference/spanner/databases/ddl/update)\ncommand to install the MySQL UDFs.\n\n\nBefore using any of the command data below,\nmake the following replacements:\n\n- \u003cvar class=\"edit\" scope=\"DATABASE_ID\" translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: the ID of the database to add the MySQL UDFs.\n- \u003cvar class=\"edit\" scope=\"INSTANCE_ID\" translate=\"no\"\u003eINSTANCE_ID\u003c/var\u003e: the ID of the instance where the database is located.\n- \u003cvar class=\"edit\" scope=\"DDL_FILE_PATH\" translate=\"no\"\u003eDDL_FILE_PATH\u003c/var\u003e: path to a file containing all the `CREATE OR REPLACE FUNCTION` statements in the [mysql_udfs.sql](https://github.com/googleapis/spanner-sql-udf/blob/main/mysql/mysql_udfs.sql) file.\n\n\nExecute the\n\nfollowing\n\ncommand:\n\n#### Linux, macOS, or Cloud Shell\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud spanner databases ddl update DATABASE_ID \\\n--instance=INSTANCE_ID \\\n--ddl-file=DDL_FILE_PATH\n```\n\n#### Windows (PowerShell)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud spanner databases ddl update DATABASE_ID `\n--instance=INSTANCE_ID `\n--ddl-file=DDL_FILE_PATH\n```\n\n#### Windows (cmd.exe)\n\n**Note:** Ensure you have initialized the Google Cloud CLI with authentication and a project by running either [gcloud init](/sdk/gcloud/reference/init); or [gcloud auth login](/sdk/gcloud/reference/auth/login) and [gcloud config set project](/sdk/gcloud/reference/config/set). \n\n```bash\ngcloud spanner databases ddl update DATABASE_ID ^\n--instance=INSTANCE_ID ^\n--ddl-file=DDL_FILE_PATH\n```\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Learn about all the Spanner supported [MySQL user-defined functions](/spanner/docs/reference/mysql/user_defined_functions_all)."]]