This page describes how to configure database flags for Cloud SQL, and lists the flags that you can set for your instance. You use database flags for many operations, including adjusting MySQL parameters, adjusting options, and configuring and tuning an instance.
In some cases, setting
one flag may require that you set another flag to fully enable the
functionality you want to use. For example, to enable
slow query logging,
you must set both the slow_query_log
flag to on
and the log_output
flag
to FILE
to make your logs available using the Google Cloud console Logs Explorer.
When you set, remove, or modify a flag for a database instance, the database might be restarted. The flag value is then persisted for the instance until you remove it. If the instance is the source of a replica, and the instance is restarted, the replica is also restarted to align with the current configuration of the instance.
Configure database flags
The following sections cover common flag management tasks.
Set a database flag
Console
- In the Google Cloud console, select the project that contains the Cloud SQL instance for which you want to set a database flag.
- Open the instance and click Edit.
- Go to the Flags section.
- To set a flag that has not been set on the instance before, click Add item, choose the flag from the drop-down menu, and set its value.
- Click Save to save your changes.
- Confirm your changes under Flags on the Overview page.
gcloud
Edit the instance:
gcloud sql instances patch INSTANCE_NAME --database-flags=FLAG1=VALUE1,FLAG2=VALUE2
This command will overwrite all database flags previously set. To keep those and add new ones, include the values for all flags you want set on the instance; any flag not specifically included is set to its default value. For flags that don't take a value, specify the flag name followed by an equals sign ("=").
For example, to set the general_log
,
skip_show_database
, and wait_timeout
flags, you
can use the following command:
gcloud sql instances patch INSTANCE_NAME \ --database-flags=general_log=on,skip_show_database=on,wait_timeout=200000
Terraform
To add database flags, use a Terraform resource.
Apply the changes
To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.
Prepare Cloud Shell
- Launch Cloud Shell.
-
Set the default Google Cloud project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also called a root module).
-
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tf
extension—for examplemain.tf
. In this tutorial, the file is referred to asmain.tf
.mkdir DIRECTORY && cd DIRECTORY && touch main.tf
-
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created
main.tf
.Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
- Review and modify the sample parameters to apply to your environment.
- Save your changes.
-
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the
-upgrade
option:terraform init -upgrade
Apply the changes
-
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
-
Apply the Terraform configuration by running the following command and entering
yes
at the prompt:terraform apply
Wait until Terraform displays the "Apply complete!" message.
- Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
Delete the changes
To delete your changes, do the following:
- To disable deletion protection, in your Terraform configuration file set the
deletion_protection
argument tofalse
.deletion_protection = "false"
- Apply the updated Terraform configuration by running the following command and
entering
yes
at the prompt:terraform apply
-
Remove resources previously applied with your Terraform configuration by running the following command and entering
yes
at the prompt:terraform destroy
REST v1
To set a flag for an existing database:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [ { "name": "flag_name", "value": "flag_value" } ] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
For example, to set the general_log
flag for an existing
database use:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [ { "name": "general_log", "value": "on" } ] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If there are existing flags configured for the database, modify the previous
command to include them. The PATCH
command overwrites the existing
flags with the ones specified in the request.
REST v1beta4
To set a flag for an existing database:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [ { "name": "flag_name", "value": "flag_value" } ] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
For example, to set the general_log
flag for an existing
database use:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [ { "name": "general_log", "value": "on" } ] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If there are existing flags configured for the database, modify the previous
command to include them. The PATCH
command overwrites the existing
flags with the ones specified in the request.
Clear all flags to their default values
Console
- In the Google Cloud console, select the project that contains the Cloud SQL instance for which you want to clear all flags.
- Open the instance and click Edit.
- Open the Database flags section.
- Click the X next to all of the flags shown.
- Click Save to save your changes.
gcloud
Clear all flags to their default values on an instance:
gcloud sql instances patch INSTANCE_NAME \ --clear-database-flags
You are prompted to confirm that the instance will be restarted.
REST v1
To clear all flags for an existing instance:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
REST v1beta4
To clear all flags for an existing instance:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
Request JSON body:
{ "settings": { "databaseFlags": [] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
View current values of database flags
To view all current values of the MySQL system variables, log into your instance with themysql
client and enter the following statement:
SHOW VARIABLES;
Note that you can change the value only for supported flags (as listed below).
Determine which database flags have been set for an instance
To see which flags have been set for a Cloud SQL instance:
Console
- In the Google Cloud console, select the project that contains the Cloud SQL instance for which you want to see the database flags that have been set.
- Select the instance to open its Instance Overview page.
The database flags that have been set are listed under the Database flags section.
gcloud
Get the instance state:
gcloud sql instances describe INSTANCE_NAME
In the output, database flags are listed under the settings
as
the collection databaseFlags
. For more information
about the representation of the flags in the output, see
Instances Resource Representation.
REST v1
To list flags configured for an instance:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
In the output, look for the databaseFlags
field.
REST v1beta4
To list flags configured for an instance:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- instance-id: The instance ID
HTTP method and URL:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
In the output, look for the databaseFlags
field.
Flags managed by Cloud SQL
Cloud SQL adjusts certain system flags depending on the instance machine type.
- innodb_buffer_pool_instances
-
- 1 for db-f1-micro and db-g1-small.
- 1 if RAM < 7.5 GB.
- 2 if 7.5 GB <= RAM < 13 GB.
- 4 if 13 GB <= RAM < 26 GB.
- 8 if RAM >= 26 GB.
Supported flags
The flags supported in Cloud SQL are the most commonly requested flags for MySQL. Flags not mentioned below are not supported.
For a given flag, Cloud SQL might support a different value or range from the corresponding MySQL parameter or option.
The flags apply to all versions of MySQL supported by Cloud SQL except where noted.
A | B | C | D | E | F | G | H | I | L | M | N | O | P | Q | R | S | T | U | W
Cloud SQL Flag | Type Acceptable Values and Notes |
Restart Required? |
---|---|---|
activate_all_roles_on_login |
boolean on | off
default: off
|
No |
autocommit |
boolean on | off
default: on
|
No |
auto_increment_increment | integer 1 ... 65535 |
No |
auto_increment_offset | integer 1 ... 65535 |
No |
automatic_sp_privileges |
boolean on | off
default: on
|
No |
back_log | integer 1 ... 65535
default: max_connections
|
Yes |
binlog_cache_size | integer 4096 ... 9223372036854775807 |
No |
binlog_expire_logs_seconds | integer 0 or 86400 (1 day) ... 4294967295 (max value) Default is 2592000, which equals 30 days. See the Tips section for more information about this flag. |
No |
binlog_group_commit_sync_delay | 0 ... 1000000
Supported in MySQL 5.7 and later Default is 0. |
No |
binlog_group_commit_sync_no_delay_count | 0 ... 1000000
Supported in MySQL 5.7 and later Default is 0. |
No |
binlog_gtid_simple_recovery |
boolean on | off
default: on
|
Yes |
binlog_order_commits |
boolean on | off
default: on
See the Tips section for more information about this flag. |
No |
binlog_row_image | enumeration full (default), minimal , or noblob |
No |
binlog_row_metadata | enumeration full or minimal (default) |
No |
binlog_row_value_options | string PARTIAL_JSON |
No |
binlog_rows_query_log_events |
boolean on | off
default: off
|
No |
binlog_stmt_cache_size | 4096 ... 9223372036854775807 |
No |
binlog_transaction_dependency_history_size | integer
For information about how to use this flag and its acceptable values, see Configuring parallel replication. |
No |
binlog_transaction_dependency_tracking | enumeration
For information about how to use this flag and its acceptable values, see Configuring parallel replication. This flag is not supported in MySQL 8.4. |
No |
block_encryption_mode | string aes-keylen-mode
default: aes-128-ECB
|
No |
bulk_insert_buffer_size | integer 0 ... 4294967295
default: 8388608 |
No |
collation_connection | string
default: MySQL 8.0 and later - utf8mb4_0900_ai_ci See the Tips section for more information about this flag. |
No |
collation_server | string
default: MySQL 5.7 - utf8_general_ci MySQL 8.0 and later - utf8mb4_0900_ai_ci |
No |
character_set_client | string default: MySQL 5.7: utf8
MySQL 8.0 and later: utf8mb4
See the Tips section for more information about this flag. |
No |
character_set_connection | string
default: MySQL 5.7: utf8
MySQL 8.0 and later: utf8mb4
See the Tips section for more information about this flag. |
No |
character_set_results | string utf8 or utf8mb4 default: MySQL 5.7: utf8
MySQL 8.0 and later: utf8mb4
See the Tips section for more information about this flag. |
No |
character_set_server | string utf8 or utf8mb4 (recommended) |
Yes |
check_proxy_users |
boolean on | off
default: off
|
No |
cloudsql_allow_analyze_table | boolean on | off
default: off
|
No |
cloudsql_iam_authentication | boolean on | off
default: off
Supported in MySQL 5.7 and later for Cloud SQL. |
No |
cloudsql_ignore_innodb_encryption | boolean on | off
default: off
|
No |
cloudsql_mysql_audit_data_masking_cmds |
string "" , dql , dml , ddl , dcl , show , call , create_udf , drop_function , create_procedure , create_function , drop_procedure , alter_procedure , alter_function , create_trigger , drop_trigger , create_event , alter_event , drop_event , create_db , drop_db , alter_db , create_user , drop_user , rename_user , alter_user , create_table , create_index , alter_table , drop_table , drop_index , create_view , drop_view , rename_table , update , insert , insert_select , delete , truncate , replace , replace_select , delete_multi , update_multi , load , select , call_procedure , connect ,
disconnect , grant , revoke , revoke_all , show_triggers , show_create_proc , show_create_func , show_procedure_code , show_function_code , show_create_event , show_events , show_create_trigger , show_grants , show_binlog_events , show_relaylog_events
default: create_user , alter_user ,
grant , and update
|
No |
cloudsql_mysql_audit_data_masking_regex |
string max_string_length: 2048
default: Click here. |
No |
cloudsql_mysql_audit_log_write_period |
integer 0...5000 milliseconds
default: 500 milliseconds
|
No |
cloudsql_mysql_audit_max_query_length |
integer -1...1073741824
default: -1
|
No |
cloudsql_vector |
boolean on | off
default: off
|
Yes |
cloudsql_vector_max_mem_size |
integer 1073741824...innodb_buffer_pool_size/2
default: 1073741824 in bytes
|
Yes |
completion_type | enumeration NO_CHAIN (default),
CHAIN , or RELEASE |
No |
concurrent_insert | enumeration NEVER , AUTO
(default), or ALWAYS |
No |
connect_timeout | integer 2 ... 31536000
default: 10 |
No |
cte_max_recursion_depth | integer 0 ... 4294967295
default: 1000 |
No |
default_authentication_plugin | string mysql_native_password|caching_sha2_password
|
Yes |
default_password_lifetime | integer 0...65535
default: 0
|
No |
default_time_zone | string There are two ways to specify timezones: as timezone offsets and timezone names. For example, +00:00 is the
timezone offset for London (which is in the UTC timezone), and
Europe/London is its timezone name.
You use values to specify timezone offsets, from When using timezone names, automatic adjustment to daylight saving time is supported. When using timezone offsets, it isn't supported. See a list of timezone names that Cloud SQL for MySQL supports. You must update this flag manually, on the primary instance and on all read replicas, to account for it. To set the timezone without causing a restart of the Cloud SQL instance, use the |
Yes |
default_week_format | integer 0 ... 7
default: 0 |
No |
delay_key_write | enumeration OFF , ON (default),
or ALL |
No |
disconnect_on_expired_password | boolean on | off
default: on
|
Yes |
div_precision_increment | integer 0 ... 30
default: 4 |
No |
end_markers_in_json |
boolean on | off
default: off
|
No |
eq_range_index_dive_limit | integer 0 ... 2147483647 |
No |
event_scheduler | boolean on | off
If you are using the Event Scheduler, configure your instance with an activation policy of ALWAYS to ensure that scheduled events run. See the Tips section for more information about this flag. |
No |
expire_logs_days | integer 0 ... 99 Default is 0, which means no automatic removal. Note: This flag is not supported in MySQL 8.4.
Use |
No |
explicit_defaults_for_timestamp | boolean on | off |
No |
flush_time | integer 0 ... 31536000
default: 0 |
No |
foreign_key_checks |
boolean on | off
default: on
See the Tips section for more information about this flag. |
No |
ft_max_word_len | integer 10 ... 252 |
Yes |
ft_min_word_len | integer 1 ... 16 |
Yes |
ft_query_expansion_limit | integer 0 ... 1000 |
Yes |
ft_stopword_file | string |
Yes |
general_log | boolean on | off
See the Tips section for more information about general logs. |
No |
generated_random_password_length | integer 5-255
default: 20
|
No |
group_concat_max_len | integer 4 ... 17179869184 |
No |
gtid_executed_compression_period | integer 0 ... 4294967295
default (up to version 8.0.22): 1000
default (version 8.0.23+): 0
|
No |
histogram_generation_max_mem_size | integer 1000000 ... 4294967295
default: 20000000
|
No |
init_connect | string |
No |
innodb_adaptive_hash_index | boolean on | off |
No |
innodb_adaptive_hash_index_parts | integer 1 ... 512 |
Yes |
innodb_adaptive_max_sleep_delay | integer 0 ... 1000000 |
No |
innodb_autoextend_increment | integer 1 ... 1000 |
No |