Install MySQL user-defined functions

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 .

Required roles

To get the permissions that you need to install the MySQL functions, ask your administrator to grant you the Cloud Spanner Database Admin ( roles/spanner.databaseAdmin ) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations .

You might also be able to get the required permissions through custom roles or other predefined roles .

Install the MySQL user-defined functions

You can install the MySQL user-defined functions in a Spanner database in the following ways:

Google Cloud console

  1. In the Google Cloud console, go to the Spanner Instancespage.

    Go to the Instances page

  2. Click the instance containing the database.

  3. Click the database.

  4. Click the Write DDLbutton to open Spanner Studio.

  5. Copy the entire content of the DDL file in the mysql_udfs.sql file.

  6. In a SQL editor tab, paste the copied content from the DDL file,

  7. Click Run.

gcloud

You can use the gcloud spanner database ddl update command 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 FUNCTION statements in the mysql_udfs.sql file.

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud  
spanner  
databases  
ddl  
update  
 DATABASE_ID 
  
 \ 
--instance = 
 INSTANCE_ID 
  
 \ 
--ddl-file = 
 DDL_FILE_PATH 

Windows (PowerShell)

gcloud  
spanner  
databases  
ddl  
update  
 DATABASE_ID 
  
 ` 
--instance = 
 INSTANCE_ID 
  
 ` 
--ddl-file = 
 DDL_FILE_PATH 

Windows (cmd.exe)

gcloud  
spanner  
databases  
ddl  
update  
 DATABASE_ID 
  
^
--instance = 
 INSTANCE_ID 
  
^
--ddl-file = 
 DDL_FILE_PATH 

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: