Install MySQL user-defined functions Stay organized with collections Save and categorize content based on your preferences.
This document describes how to install a predefined library of MySQL functionsin a Spanner database. You can add these functions to yourdatabase 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 environmentsdirectly within Spanner.
For more information about the MySQL functions that Spannersupports, seeMySQL functions.
Required roles
To get the permissions that you need to install the MySQL functions, ask your administrator to grant you theCloud Spanner Database Admin (roles/spanner.databaseAdmin) IAM role on your project. For more information about granting roles, seeManage access to projects, folders, and organizations.
You might also be able to get the required permissions throughcustom roles or otherpredefined roles.
Install the MySQL user-defined functions
You can install the MySQL user-defined functions in a Spannerdatabase in the following ways:
Google Cloud console
In the Google Cloud console, go to the SpannerInstances page.
Click the instance containing the database.
Click the database.
Click theWrite DDL button to open Spanner Studio.
Copy the entire content of the DDL file in the
mysql_udfs.sqlfile.In a SQL editor tab, paste the copied content from the DDL file,
ClickRun.
gcloud
You can use thegcloud spanner database ddl updatecommand to install the MySQL UDFs.
Before using any of the command data below, make the following replacements:
- DATABASE_ID: the ID of the database to add the MySQL UDFs.
- INSTANCE_ID: the ID of the instance where the database is located.
- DDL_FILE_PATH: path to a file containing all the
CREATE OR REPLACE FUNCTIONstatements in themysql_udfs.sql file.
Execute the following command:
Linux, macOS, or Cloud Shell
Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.gcloudspannerdatabasesddlupdateDATABASE_ID\--instance=INSTANCE_ID\--ddl-file=DDL_FILE_PATH
Windows (PowerShell)
Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.gcloudspannerdatabasesddlupdateDATABASE_ID`--instance=INSTANCE_ID`--ddl-file=DDL_FILE_PATH
Windows (cmd.exe)
Note: Ensure you have initialized the Google Cloud CLI with authentication and a project by running eithergcloud init; orgcloud auth login andgcloud config set project.gcloudspannerdatabasesddlupdateDATABASE_ID^--instance=INSTANCE_ID^--ddl-file=DDL_FILE_PATH
What's next
- Learn about all the Spanner supportedMySQL user-defined functions.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.