配置数据库标志

本页面介绍如何为 Cloud SQL 配置数据库标志,并列出了可以为实例设置的标志。您可以将数据库标志用于许多操作,包括调整 MySQL 参数、调整选项以及配置和优化实例。

在某些情况下,设置一个标志时,可能需要设置另一个标志才能完全启用所需功能。例如,如需启用慢查询日志记录,您必须将 slow_query_log 标志设置为 on 并将 log_output 标志设置为 FILE,才能使用 Google Cloud 控制台 Logs Explorer 来阅读日志。

当您设置、移除或修改数据库实例的标志时,该数据库可能会重启。除非您主动移除,否则实例的此标志值会一直保留。如果实例是副本的来源,并且实例已经重启,那么系统还会重启副本以与实例的当前配置保持一致。

配置数据库标志

设置数据库标志

控制台

  1. Google Cloud 控制台中,选择包含要为其设置数据库标志的 Cloud SQL 实例的项目。
  2. 打开实例,然后点击修改
  3. 向下滚动至标志部分。
  4. 要在实例上设置先前未设置的标志,请点击添加一项,从下拉菜单中选择该标志,然后设置其值。
  5. 点击保存以保存更改。
  6. 在“概览”页的标志下确认更改。

gcloud

修改实例:

gcloud sql instances patch INSTANCE_NAME --database-flags=FLAG1=VALUE1,FLAG2=VALUE2

此命令将覆盖之前设置的所有数据库标志。如需保留这些标志并添加新标志,请为您要在实例上设置的所有标志添加值;任何未明确添加的标志都会设置为默认值。对于不带值的标志,请指定标志名称并后接一个等号(“=”)。

例如,如需设置 general_logskip_show_databasewait_timeout 标志,您可以使用以下命令:

gcloud sql instances patch INSTANCE_NAME \
  --database-flags=general_log=on,skip_show_database=on,wait_timeout=200000

Terraform

如需添加数据库标志,请使用 Terraform 资源

resource "google_sql_database_instance" "instance" {
  database_version = "MYSQL_8_0"
  name             = "mysql-instance"
  region           = "us-central1"
  settings {
    database_flags {
      name  = "general_log"
      value = "on"
    }
    database_flags {
      name  = "skip_show_database"
      value = "on"
    }
    database_flags {
      name  = "wait_timeout"
      value = "200000"
    }
    disk_type = "PD_SSD"
    tier      = "db-n1-standard-2"
  }
  # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
  # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
  deletion_protection = false
}

应用更改

如需在 Google Cloud 项目中应用 Terraform 配置,请完成以下部分中的步骤。

准备 Cloud Shell

  1. 启动 Cloud Shell
  2. 设置要在其中应用 Terraform 配置的默认 Google Cloud 项目。

    您只需为每个项目运行一次以下命令,即可在任何目录中运行它。

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    如果您在 Terraform 配置文件中设置显式值,则环境变量会被替换。

准备目录

每个 Terraform 配置文件都必须有自己的目录(也称为“根模块”)。

  1. Cloud Shell 中,创建一个目录,并在该目录中创建一个新文件。文件名必须具有 .tf 扩展名,例如 main.tf。在本教程中,该文件称为 main.tf
    mkdir DIRECTORY && cd DIRECTORY && touch main.tf
  2. 如果您按照教程进行操作,可以在每个部分或步骤中复制示例代码。

    将示例代码复制到新创建的 main.tf 中。

    (可选)从 GitHub 中复制代码。如果端到端解决方案包含 Terraform 代码段,则建议这样做。

  3. 查看和修改要应用到您的环境的示例参数。
  4. 保存更改。
  5. 初始化 Terraform。您只需为每个目录执行一次此操作。
    terraform init

    (可选)如需使用最新的 Google 提供程序版本,请添加 -upgrade 选项:

    terraform init -upgrade

应用更改

  1. 查看配置并验证 Terraform 将创建或更新的资源是否符合您的预期:
    terraform plan

    根据需要更正配置。

  2. 通过运行以下命令并在提示符处输入 yes 来应用 Terraform 配置:
    terraform apply

    等待 Terraform 显示“应用完成!”消息。

  3. 打开您的 Google Cloud 项目以查看结果。在 Google Cloud 控制台的界面中找到资源,以确保 Terraform 已创建或更新它们。

删除更改

如需删除更改,请执行以下操作:

  1. 如需停用删除防护,请在 Terraform 配置文件中将 deletion_protection 参数设置为 false
    deletion_protection =  "false"
  2. 运行以下命令并在提示符处输入 yes,以应用更新后的 Terraform 配置:
    terraform apply
  1. 运行以下命令并在提示符处输入 yes,以移除之前使用 Terraform 配置应用的资源:

    terraform destroy

REST v1

设置现有数据库的标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "flag_name",
        "value": "flag_value"
      }
    ]
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

例如,如需为现有数据库设置 general_log 标志,请按如下所示操作:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "general_log",
        "value": "on"
      }
    ]
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

如果数据库存在已配置的现有标志,请修改先前的命令,将其包含在内。PATCH 命令会使用请求中指定的标志覆盖现有标志。

REST v1beta4

设置现有数据库的标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "flag_name",
        "value": "flag_value"
      }
    ]
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

例如,如需为现有数据库设置 general_log 标志,请按如下所示操作:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "general_log",
        "value": "on"
      }
    ]
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

如果数据库存在已配置的现有标志,请修改先前的命令,将其包含在内。PATCH 命令会使用请求中指定的标志覆盖现有标志。

将所有标志恢复为其默认值

控制台

  1. Google Cloud 控制台中,选择包含要清除所有标志的 Cloud SQL 实例的项目。
  2. 打开实例,然后点击修改
  3. 打开数据库标志部分。
  4. 点击显示的所有标志旁的 X
  5. 点击保存以保存更改。

gcloud

将实例上的所有标志恢复为其默认值:

gcloud sql instances patch INSTANCE_NAME \
--clear-database-flags

系统会提示您确认实例将重启。

REST v1

清除现有实例的所有标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags": []
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

REST v1beta4

清除现有实例的所有标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

请求 JSON 正文:

{
  "settings":
  {
    "databaseFlags": []
  }
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

查看数据库标志的当前值

如需查看 MySQL 系统变量的所有当前值,请使用 mysql 客户端登录到您的实例,然后输入以下语句:

 SHOW VARIABLES;

请注意,您只能更改受支持标志的值(如下所列)。

确定已为实例设置的数据库标志

如需查看已为 Cloud SQL 实例设置的标志:

控制台

  1. Google Cloud 控制台中,选择包含要查看其已设置数据库标志的 Cloud SQL 实例的项目。
  2. 选择实例,打开其实例概览页面。

    数据库标志部分列出了已设置的数据库标志。

gcloud

获取实例状态:

gcloud sql instances describe INSTANCE_NAME

在输出中,数据库标志作为 databaseFlags 集合列在 settings 下。要详细了解输出中标志的表示法,请参阅实例资源表示法

REST v1

列出实例的已配置标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

在输出中,查找 databaseFlags 字段。

REST v1beta4

列出实例的已配置标志:

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • instance-id:实例 ID

HTTP 方法和网址:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

在输出中,查找 databaseFlags 字段。

由 Cloud SQL 管理的标志

Cloud SQL 会根据实例机器类型调整某些系统标志。

innodb_buffer_pool_instances
  • 对于 db-f1-micro 和 db-g1-small,此标志的值为 1。
  • 如果 RAM 小于 7.5 GB,则为 1。
  • 如果 7.5 GB <= RAM 小于 13 GB,则为 2。
  • 4(如果 13 GB <= RAM < 26 GB)。
  • 如果 RAM 大于等于 26 GB,则为 8。

支持的标志

Cloud SQL 中支持的标志是请求最频繁的 MySQL 标志。 下面未提及的标志不受支持。

对于给定标志,Cloud SQL 支持的值或范围可能与对应的 MySQL 参数或选项不同。

除非另有说明,否则标志适用于 Cloud SQL 支持的所有 MySQL 版本。

A | B | C | D | E | F | G | H | I | L | M | N | O | P | Q | R | S | T | U | W

Cloud SQL 标志 类型
可接受值及备注
是否需要
重启?
activate_all_roles_on_login boolean
on | off
默认值:off
autocommit boolean
on | off
默认值:on
auto_increment_increment integer
1 65535
auto_increment_offset integer
1 65535
automatic_sp_privileges boolean
on | off
默认值:on
back_log integer
1 ... 65535
默认值:max_connections
binlog_cache_size integer
4096 9223372036854775807
binlog_expire_logs_seconds integer
086400 (1 day) ... 4294967295 (max value)
默认值为 2592000,相当于 30 天。

要详细了解此标志,请参阅提示部分。

binlog_group_commit_sync_delay 0 ... 1000000

MySQL 5.78.0 支持

默认值为 0

binlog_group_commit_sync_no_delay_count 0 ... 1000000

MySQL 5.78.0 支持

默认值为 0

binlog_gtid_simple_recovery boolean
on | off
默认值:on
binlog_order_commits boolean
on | off
默认值:on

要详细了解此标志,请参阅提示部分。

binlog_row_image enumeration
full(默认)、minimalnoblob
binlog_row_metadata enumeration
fullminimal(默认)
binlog_row_value_options string
PARTIAL_JSON
binlog_rows_query_log_events boolean
on | off
默认值:off
binlog_stmt_cache_size 4096 9223372036854775807
binlog_transaction_dependency_history_size integer

如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

binlog_transaction_dependency_tracking enumeration

如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

block_encryption_mode string
aes-keylen-mode
默认值:aes-128-ECB
bulk_insert_buffer_size integer
0 ... 4294967295
默认值:8388608
collation_connection string
默认值:
MySQL 8.0 - utf8mb4_0900_ai_ci

要详细了解此标志,请参阅提示部分。

collation_server string
默认值:
MySQL 5.7 - utf8_general_ci
MySQL 8.0 - utf8mb4_0900_ai_ci
character_set_client string

默认值:
MySQL 5.7:utf8
MySQL 8.0:utf8mb4

要详细了解此标志,请参阅提示部分。

character_set_connection string
默认值:
MySQL 5.7:utf8
MySQL 8.0:utf8mb4

要详细了解此标志,请参阅提示部分。

character_set_results string
utf8utf8mb4
默认值:
MySQL 5.7:utf8
MySQL 8.0:utf8mb4

要详细了解此标志,请参阅提示部分。

character_set_server string
utf8utf8mb4(推荐)
check_proxy_users boolean
on | off
默认值:off
cloudsql_allow_analyze_table boolean on | off
默认值:off
cloudsql_iam_authentication boolean on | off
默认值:off
MySQL 5.7 for Cloud SQL 和 MySQL 8.0 for Cloud SQL 支持此标志。
cloudsql_ignore_innodb_encryption boolean on | off
默认值:off
cloudsql_mysql_audit_data_masking_cmds string
""dqldmlddldclshowcallcreate_udfdrop_functioncreate_procedurecreate_functiondrop_procedurealter_procedurealter_functioncreate_triggerdrop_triggercreate_eventalter_eventdrop_eventcreate_dbdrop_dbalter_dbcreate_userdrop_userrename_useralter_usercreate_tablecreate_indexalter_tabledrop_tabledrop_indexcreate_viewdrop_viewrename_tableupdateinsertinsert_selectdeletetruncatereplacereplace_selectdelete_multiupdate_multiloadselectcall_procedureconnectdisconnectgrantrevokerevoke_allshow_triggersshow_create_procshow_create_funcshow_procedure_codeshow_function_codeshow_create_eventshow_eventsshow_create_triggershow_grantsshow_binlog_eventsshow_relaylog_events

默认值:create_useralter_usergrantupdate
cloudsql_mysql_audit_data_masking_regex string
max_string_length: 2048
默认值:点击此处
cloudsql_mysql_audit_log_write_period integer
0...5000 毫秒
默认值:500 毫秒
cloudsql_mysql_audit_max_query_length integer
-1...1073741824
默认值:-1
cloudsql_vector boolean on | off
默认值:off
cloudsql_vector_max_mem_size integer
1073741824...innodb_buffer_pool_size/2
默认值:1073741824(以字节为单位)
completion_type enumeration
NO_CHAIN(默认值)、CHAINRELEASE
concurrent_insert enumeration
NEVERAUTO(默认值)或 ALWAYS
connect_timeout integer
2 ... 31536000
默认值:10
cte_max_recursion_depth integer
0 ... 4294967295
默认值:1000
default_authentication_plugin string
mysql_native_password|caching_sha2_password
default_password_lifetime integer 0...65535
默认值:0
default_time_zone string
指定时区的方法有两种:作为时区偏移量和时区名称。例如,+00:00 是伦敦的时区偏移量(采用 UTC 时区),Europe/London 是其时区名称。

您可以使用值来指定时区偏移量,范围为 -12:59+13:00。必须添加前导零。

使用时区名称时,支持自动调整夏令时。使用时区偏移时,它不受支持。查看 Cloud SQL for MySQL 支持的时区名称列表。您必须在主实例和所有读取副本上手动更新此标志来反映夏令时。

如需在不重启 Cloud SQL 实例的情况下设置时区,请使用带 init_connect 标志的 set time_zone=timezone_offsettimezone_name 命令。

default_week_format integer
0 ... 7
默认值:0
delay_key_write enumeration
OFFON(默认值)或 ALL
disconnect_on_expired_password boolean on | off
默认值:on
div_precision_increment integer
0 ... 30
默认值:4
end_markers_in_json boolean
on | off
默认值:off
eq_range_index_dive_limit integer
0 2147483647
event_scheduler boolean
on | off

如果您使用的是 Event Scheduler,请将实例的激活政策配置为 ALWAYS,以确保预定事件正常运行。

要详细了解此标志,请参阅提示部分。

expire_logs_days integer
0 ... 99
默认值为 0,表示不可自动移除。

要详细了解此标志,请参阅提示部分。

explicit_defaults_for_timestamp boolean
on | off

flush_time integer
0 ... 31536000
默认值:0
foreign_key_checks boolean
on | off
默认值:on

要详细了解此标志,请参阅提示部分。

ft_max_word_len integer
10 252
ft_min_word_len integer
1 16
ft_query_expansion_limit integer
0 1000
ft_stopword_file string
general_log boolean
on | off

要详细了解常规日志,请参阅提示部分。

generated_random_password_length integer 5-255
默认值:20
group_concat_max_len integer
4 17179869184
gtid_executed_compression_period integer
0 ... 4294967295
默认值(8.0.22 版及更低版本):1000
默认值(8.0.23+ 版):0
histogram_generation_max_mem_size integer
1000000 ... 4294967295
默认值:20000000
init_connect string
innodb_adaptive_hash_index boolean
on | off
innodb_adaptive_hash_index_parts integer
1 512
innodb_adaptive_max_sleep_delay integer
0 1000000
innodb_autoextend_increment integer
11000
innodb_autoinc_lock_mode integer
0 2
innodb_buffer_pool_chunk_size integer
1048576(innodb_buffer_pool_size/innodb_buffer_pool_instances)

此标志值取决于 innodb_buffer_pool_sizeinnodb_buffer_pool_instances。MySQL 可以根据这两个标志自动调整 innodb_buffer_pool_chunk_size 的值。

innodb_buffer_pool_dump_pct integer
1 ... 100
默认值:25
innodb_buffer_pool_dump_at_shutdown boolean
on | off
innodb_buffer_pool_dump_now boolean
on | off

如需详细了解此标志,请参阅提示部分。

innodb_buffer_pool_instances integer
1 64
innodb_buffer_pool_load_abort boolean
on | off

如需详细了解此标志,请参阅提示部分。

innodb_buffer_pool_load_at_startup boolean
on | off
innodb_buffer_pool_load_now boolean
on | off

如需详细了解此标志,请参阅提示部分。

innodb_buffer_pool_size integer

为 MySQL 5.6 设置此标志需要重启。要详细了解此标志,请参阅提示部分。

innodb_change_buffer_max_size integer
0 50
innodb_change_buffering string

选项:noneinsertsdeleteschangespurgesall

innodb_checksum_algorithm string

选项:crc32strict_crc32innodbstrict_innodnonestrict_none

innodb_cmp_per_index_enabled boolean
on | off
innodb_commit_concurrency integer
01000
innodb_compression_failure_threshold_pct integer
0100
innodb_compression_level integer
09
innodb_compression_pad_pct_max integer
075
innodb_concurrency_tickets integer
1 4294967295
innodb_deadlock_detect boolean
on | off

在 MySQL 5.78.0 中受支持。

默认:on

innodb_disable_sort_file_cache boolean
on | off
innodb_doublewrite_batch_size integer
0 ... 256
默认值:0
innodb_doublewrite_files integer
2 128
innodb_doublewrite_pages integer
4 ... 512
默认值:64
innodb_file_per_table boolean
on | off

要详细了解此标志,请参阅提示部分。

innodb_fill_factor integer
10 100
innodb_flush_log_at_timeout double
0.00012700
默认:1

在 MySQL 5.78.0 中受支持。

要详细了解此标志,请参阅提示部分。

innodb_flush_log_at_trx_commit integer
1, 2
默认:1

默认情况下,如果您提升启用了此标志的副本,则此标志会自动移除,导致提升的副本具有完整的耐用性。如需将此标志与提升的副本搭配使用,您可以在提升后将标志更新为副本。

要详细了解此标志,请参阅提示部分。

innodb_flush_neighbors enumeration
02

在 MySQL 5.65.78.0 中受支持。

默认值:

  • MySQL 5.6: 0
  • MySQL 5.7: 2
  • MySQL 8.0: 2
  • innodb_flush_sync boolean
    on | off
    innodb_ft_aux_table string

    要详细了解此标志,请参阅提示部分。

    innodb_ft_cache_size integer
    1600000 80000000
    innodb_ft_enable_diag_print boolean
    on | off
    innodb_ft_enable_stopword boolean
    on | off
    innodb_ft_max_token_size integer
    10 252

    仅受 MySQL 5.6 及更高版本支持。

    innodb_ft_min_token_size integer
    0 16

    仅受 MySQL 5.6 及更高版本支持。

    innodb_ft_num_word_optimize integer
    1000 10000
    innodb_ft_result_cache_limit integer
    1000000 4294967295
    innodb_ft_server_stopword_table string

    仅受 MySQL 5.6 及更高版本支持。

    innodb_ft_sort_pll_degree integer
    1 32
    innodb_ft_total_cache_size integer
    32000000 1600000000
    innodb_ft_user_stopword_table string
    innodb_io_capacity integer
    100 ... 100000
    默认值:5000

    在 MySQL 5.65.78.0 中受支持。

    如需详细了解如何配置磁盘性能,请参阅配置磁盘以满足性能要求中的 E2 虚拟机表。

    innodb_io_capacity_max integer
    100 ... 100000
    默认值:10000

    在 MySQL 5.65.78.0 中受支持。

    如需详细了解如何配置磁盘性能,请参阅配置磁盘以满足性能要求中的 E2 虚拟机表。

    innodb_large_prefix boolean
    on | off

    仅受 MySQL 5.6 支持。

    innodb_lock_wait_timeout integer
    1 1073741824
    innodb_log_buffer_size integer
    262144 4294967295
    innodb_log_checksums boolean
    on | off
    默认值:on
    innodb_log_compressed_pages boolean
    on | off
    默认值:on
    innodb_log_file_size integer
    MySQL 5.6:1048576274877906944
    MySQL 5.7:4194304274877906944
    innodb_log_spin_cpu_abs_lwm integer
    0 ... 4294967295
    默认值:80
    innodb_log_spin_cpu_pct_hwm integer
    0 ... 100
    默认值:50
    innodb_log_wait_for_flush_spin_hwm integer
    0 ... 4294967295
    默认值:400
    innodb_log_write_ahead_size integer
    512 ... 65536
    默认值:8192
    innodb_lru_scan_depth integer
    100 9223372036854775807
    innodb_max_dirty_pages_pct float
    0 ... 99.99
    默认值:90
    innodb_max_dirty_pages_pct_lwm float
    0 ... 99.99
    默认值:10
    innodb_max_purge_lag integer
    0 ... 4294967295
    默认值:0
    innodb_max_undo_log_size integer
    10485760 ... 9223372036854775807
    默认值:1073741824
    innodb_max_purge_lag_delay integer
    0 ... 10000000
    默认值:0
    innodb_monitor_disable string
    innodb_monitor_enable string
    innodb_monitor_reset string
    countermodulepatternall
    innodb_monitor_reset_all enumeration
    有效值:countermodulepatternall
    innodb_old_blocks_pct integer
    5 95
    innodb_old_blocks_time integer
    0 4294967295
    innodb_online_alter_log_max_size integer
    65536 9223372036854775807
    innodb_open_files integer
    100 ... 2147483647
    默认值:
    MySQL 5.7:2000
    MySQL 8.0:4000
    8.0.28:否
    8.0.27:是
    innodb_optimize_fulltext_only boolean
    on | off
    innodb_page_cleaners integer
    1 ... 64
    在 MySQL 5.78.0 中受支持。 默认值:4。 对于 5.7 版,默认值为 32
    innodb_parallel_read_threads integer
    1 ... 256
    默认值:4
    innodb_print_all_deadlocks boolean
    on | off
    默认值:off
    innodb_print_ddl_logs boolean
    on | off
    innodb_purge_batch_size integer
    1 ... 5000
    默认值:300
    innodb_purge_rseg_truncate_frequency integer
    1 ... 128
    默认值:128
    innodb_purge_threads 1 ... 32

    MySQL 5.65.78.0 支持

    默认值为 1

    innodb_random_read_ahead boolean
    on | off
    innodb_read_ahead_threshold integer
    0 64
    innodb_read_io_threads integer
    164
    innodb_replication_delay integer
    0 4294967295
    innodb_rollback_on_timeout boolean
    on | off
    innodb_rollback_segments integer
    1 128
    innodb_segment_reserve_factor float
    .03 ... 40
    默认值:12.5
    innodb_sort_buffer_size integer
    65536 67108864
    innodb_spin_wait_delay integer
    MySQL 5.7:0 ... 1000000
    MySQL 8.0.13+:0 ... 1000
    默认值:6
    innodb_stats_auto_recalc boolean
    on | off
    innodb_stats_include_delete_marked boolean
    on | off
    默认值:off
    innodb_stats_method enumeration
    nulls_equal | nulls_unequal | nulls_ignored
    innodb_stats_on_metadata boolean
    on | off
    innodb_stats_persistent boolean
    on | off
    innodb_stats_persistent_sample_pages integer
    1 9223372036854775807
    innodb_stats_sample_pages integer
    1 9223372036854775807
    innodb_stats_transient_sample_pages integer
    1 9223372036854775807
    innodb_status_output boolean
    on | off
    innodb_status_output_locks boolean
    on | off
    innodb_strict_mode boolean
    on | off
    innodb_sync_array_size 1 ... 1024

    MySQL 5.65.78.0 支持

    默认值为 1

    innodb_sync_spin_loops integer
    0 ... 4294967295
    默认值:30
    innodb_table_locks boolean
    on | off
    默认值:on
    innodb_thread_concurrency integer
    0 1000
    innodb_thread_sleep_delay integer
    0 1000000
    innodb_undo_log_truncate boolean
    on | off
    默认值:on
    innodb_use_native_aio boolean
    on | off
    默认值:on
    innodb_write_io_threads integer
    1 64
    interactive_timeout integer
    1 31536000
    internal_tmp_disk_storage_engine enumeration
    INNODB | MYISAM
    默认值:INNODB
    此标志仅用于 MySQL 5.7。
    internal_tmp_mem_storage_engine enumeration
    MEMORYTempTable
    此标志仅用于 MySQL 8.0。
    join_buffer_size integer
    128 9223372036854775807
    keep_files_on_create boolean
    on | off
    默认值:off
    key_buffer_size integer
    4096 ... 4294967295
    默认值:8388608
    key_cache_age_threshold integer
    100 ... 9223372036854775807
    默认值:300
    key_cache_block_size integer
    512 ... 16384
    默认值:1024
    key_cache_division_limit integer
    1 ... 100
    默认值:100
    lc_times_names string
    en_US | cs_CZ | da_DK | nl_NL | et_EE | fr_FR | de_DE | el_GR | hu_HU | it_IT | ja_JP | ko_KR | no_NO | nb_NO | pl_PL | pt_PT | ro_RO | ru_RU | sr_RS | sk_SK | es_ES | sv_SE | uk_UA
    默认值:en_US
    local_infile boolean
    on | off
    lock_wait_timeout integer
    1 31536000
    log_bin_trust_function_creators boolean
    on | off
    log_output set
    FILE | TABLE | NONE
    log_error_verbosity integer
    1 ... 3
    默认值:
    MySQL 5.7:3
    MySQL 8.0:2
    log_queries_not_using_indexes boolean
    on | off
    log_slow_admin_statements boolean
    on | off
    默认值:off
    log_slow_extra boolean
    on | off
    默认值:off
    log_slow_replica_statements boolean
    on | off 默认值:off
    log_slow_slave_statements boolean
    on | off 默认值:off
    log_throttle_queries_not_using_indexes integer
    0 9223372036854775807
    log_timestamps string
    "UTC | SYSTEM"
    默认值:UTC
    long_query_time float
    030000000

    如果需要,Cloud SQL 可为此标志设置一个小于 1 的值。

    如果还启用了 log_queries_not_using_indexes 标志,您可能会看到查询的时间少于此处指定的时间。

    lower_case_table_names 5.7 | 8.0 integer
    01
    默认:0

    如果为此标志使用默认值 0,则表和数据库名称区分大小写。此标志设置为 1 时,表和数据库名称不区分大小写。

    对于 MySQL 5.7 实例,您可以随时更改此标志的值。如果您这样做,请务必了解此更改如何影响现有表和数据库。

    对于 MySQL 8.0 实例,您只能在创建实例时将此标志的值设置为所需的值。此值一经设置便无法更改。此外,对于现有实例,您无法更改此标志的值。

    为 MySQL 5.7 或 MySQL 8.0 实例创建读取副本时,副本会从主实例继承此标志值。

    mandatory_roles string role name
    默认值:empty string
    master_verify_checksum boolean
    on | off 默认值:off
    max_allowed_packet integer
    16384 1073741824

    如果 sql_mode=TRADITIONAL 或 sql_mode=STRICT_ALL_TABLES,则此值必须为 1024 的倍数。

    max_binlog_cache_size integer
    4096 ... 4294967296
    默认值:4294967296
    max_binlog_size integer
    4096 1073741824
    max_binlog_stmt_cache_size integer
    4096 ... 4294967296
    默认值:4294967296
    max_connect_errors integer
    1 ... 9223372036854775807
    默认值:100
    max_connections integer
    1 ... 100000
    max_digest_length integer
    0 1048576
    max_error_count integer
    0 ... 65535
    默认值:
    MySQL 5.7 或更低版本:64
    MySQL 8.0+:1024
    max_execution_time integer
    0 9223372036854775807
    max_heap_table_size integer
    16384 67108864

    要详细了解此标志,请参阅提示部分。

    max_join_size integer
    16 9223372036854775807
    max_length_for_sort_data integer
    4 8388608
    max_points_in_geometry integer
    3 1048576
    max_prepared_stmt_count integer
    0 1048576
    max_seeks_for_key integer
    1 9223372036854775807
    max_sort_length integer
    4 8388608
    max_sp_recursion_depth integer
    0 255
    max_user_connections integer
    0 4294967295
    max_write_lock_count integer
    1 9223372036854775807
    min_examined_row_limit integer
    0 ... 4294967295
    默认值:0
    myisam_data_pointer_size integer
    2...7
    默认值:6
    myisam_max_sort_file_size integer
    0...9223372036853727232
    默认值:9223372036853727232
    myisam_mmap_size integer
    7...9223372036854775807
    默认值:9223372036854775807
    myisam_sort_buffer_size integer
    4096...4294967295
    默认值:8388608
    myisam_stats_method string
    "nulls_unequal, nulls_equal, nulls_ignored"
    默认值:nulls_unequal
    myisam_use_mmap boolean
    on | off
    默认值:off
    mysql_native_password_proxy_users boolean
    on | off
    默认值:off
    net_buffer_length integer
    1024 ... 1048576
    默认值:16384
    net_read_timeout integer
    30 4294967295
    net_retry_count integer
    10 4294967295
    net_write_timeout integer
    60 4294967295
    ngram_token_size integer
    1 ... 10
    默认值:2
    optimizer_prune_level integer
    0 1
    optimizer_search_depth integer
    0 62
    optimizer_switch multi-value repeated string

    如需详细了解多个值标志,请参阅提示部分。

    optimizer_trace multi-value repeated string
    enabled=onenabled=offone_line=onone_line=off

    如需详细了解多个值标志,请参阅提示部分。

    optimizer_trace_features multi-value repeated string

    如需详细了解多个值标志,请参阅提示部分。

    optimizer_trace_max_mem_size integer
    0 9223372036854775807
    optimizer_trace_offset integer
    -9223372036854775808 9223372036854775807
    parser_max_mem_size integer
    10000000 9223372036854775807
    password_history integer 0-4294967295
    默认值:0
    password_require_current boolean on | off
    默认值:off
    password_reuse_interval integer 0-4294967295
    默认值:0
    performance_schema boolean
    on | off

    默认:off,适用于 MySQL 5.6、5.7 和 8.0(如果实例 RAM 小于 15 GB)。

    默认:on,适用于 MySQL 8.0(如果实例 RAM 大于 15 GB)

    如需详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_accounts_size integer
    -1 1048576

    如需详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_digests_size integer
    -1 1048576

    如需详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_error_size integer
    01048576
    performance_schema_events_stages_history_long_size integer
    -1 1048576
    performance_schema_events_stages_history_size integer
    -1 1024

    如需详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_statements_history_long_size integer
    -11048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_statements_history_size integer
    -1 1024

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_transactions_history_long_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_transactions_history_size integer
    -1 1024

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_waits_history_long_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_events_waits_history_size integer
    -1 1024

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_hosts_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_cond_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_cond_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_digest_length integer
    0 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_digest_sample_age integer
    0 ... 1048576
    默认值:60
    performance_schema_max_file_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_file_handles integer
    0 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_file_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_index_stat integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_memory_classes integer
    0 ... 1024

    如需详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_metadata_locks integer
    -1 104857600

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_mutex_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_mutex_instances integer
    -1 104857600

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_prepared_statements_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_program_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_rwlock_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_rwlock_instances integer
    -1 104857600

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_socket_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_socket_instances integer
    -11048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_sql_text_length integer
    01048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_stage_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_statement_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_statement_stack integer
    1 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_table_handles integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_table_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_table_lock_stat integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_thread_classes integer
    0 256

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_max_thread_instances integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_session_connect_attrs_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_setup_actors_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_setup_objects_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    performance_schema_users_size integer
    -1 1048576

    要详细了解 performance_schema 标志,请参阅提示部分。

    preload_buffer_size integer
    1024 ... 1073741824
    默认值:32768
    query_alloc_block_size integer
    1024 4294967295
    query_cache_limit integer
    0 223338299392

    此标志不适用于 MySQL 8.0,因为查询缓存自 MySQL 5.7.20 起已被弃用,并在 MySQL 8.0 中移除。

    query_cache_min_res_unit integer
    0 9223372036854775807

    此标志不适用于 MySQL 8.0,因为查询缓存自 MySQL 5.7.20 起已被弃用,并在 MySQL 8.0 中移除。

    query_cache_size integer
    0 223338299392

    此标志不适用于 MySQL 8.0,因为查询缓存自 MySQL 5.7.20 起已被弃用,并在 MySQL 8.0 中移除。

    query_cache_type enumeration
    0 2

    此标志不适用于 MySQL 8.0,因为查询缓存自 MySQL 5.7.20 起已被弃用,并在 MySQL 8.0 中移除。

    query_cache_wlock_invalidate boolean
    on | off

    此标志不适用于 MySQL 8.0,因为查询缓存自 MySQL 5.7.20 起已被弃用,并在 MySQL 8.0 中移除。

    query_prealloc_size integer
    8192 9223372036854775807
    range_alloc_block_size integer
    4096 4294967295
    range_optimizer_max_mem_size integer
    0 9223372036854775807
    read_buffer_size integer
    8192 2147483647
    read_only boolean
    on | off

    此标志不会影响副本。

    read_rnd_buffer_size integer
    1 2147483647
    regexp_stack_limit integer
    0 2147483647
    regexp_time_limit integer
    0 ... 2147483647
    默认值:32
    replica_checkpoint_group integer
    32 ... 524280
    默认值为 512。

    此标志不会影响未启用多线程的副本。

    replica_checkpoint_period integer
    1 ... 4294967295
    默认值为 300。

    单位是毫秒。

    replica_compressed_protocol boolean
    on | off
    replica_net_timeout integer
    131536000

    单位是秒。

    replica_parallel_type enumeration
    DATABASE, LOGICAL_CLOCK
    默认值:
    MySQL 8.0.26 或更早版本:DATABASE
    MySQL 8.0.27 或更高版本:LOGICAL_CLOCK

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    replica_parallel_workers integer

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    replica_pending_jobs_size_max integer

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    replica_preserve_commit_order boolean

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    replica_skip_errors string
    默认值:OFF

    如需详细了解此标志,请参阅提示部分。

    replica_sql_verify_checksum boolean
    on | off
    replica_transaction_retries integer
    0 ... 9223372036854775807
    replica_type_conversions String
    值:ALL_LOSSYALL_NON_LOSSYALL_SIGNEDALL_UNSIGNED
    replicate_do_db string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    replicate_do_table string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    replicate_ignore_db string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    replicate_ignore_table string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    replicate_wild_do_table string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    replicate_wild_ignore_table string

    如需详细了解如何使用此标志,请参阅复制过滤条件部分。

    rpl_read_size integer
    8192 ... 4294959104
    默认值:8192
    schema_definition_cache integer
    256 ... 524288
    默认值:256
    session_track_gtids string
    OFF | OWN_GTID | ALL_GTIDS
    默认值:OFF
    session_track_schema boolean
    on | off
    默认值:on
    session_track_state_change boolean
    on | off
    默认值:off
    session_track_transaction_info string
    OFF | STATE | CHARACTERISTICS
    默认值:OFF
    sha256_password_proxy_users boolean
    on | off
    默认值:off
    show_create_table_verbosity boolean
    on | off
    默认值:off
    show_compatibility_56 boolean
    on | off

    仅受 MySQL 5.7 支持。

    skip_character_set_client_handshake boolean
    on | off
    默认值:off
    skip_show_database flag
    on | off
    slave_checkpoint_group integer
    32 ... 524280
    默认值为 512。

    此标志不会影响未启用多线程的副本。

    slave_checkpoint_period integer
    1 ... 4294967295
    默认值为 300。

    单位是毫秒。

    slave_compressed_protocol boolean
    on | off
    slave_net_timeout integer
    131536000

    单位是秒。

    slave_parallel_type enumeration
    DATABASE, LOGICAL_CLOCK
    默认值:
    MySQL 8.0.26 或更早版本:DATABASE
    MySQL 8.0.27 或更高版本:LOGICAL_CLOCK

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    slave_parallel_workers integer

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    slave_preserve_commit_order boolean

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    slave_pending_jobs_size_max integer

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    slave_skip_errors string
    默认值:OFF

    如需详细了解此标志,请参阅提示部分。

    slave_sql_verify_checksum boolean
    on | off
    slave_transaction_retries integer
    0 ... 9223372036854775807
    slave_type_conversions string
    值:ALL_LOSSYALL_NON_LOSSYALL_SIGNEDALL_UNSIGNED
    slow_launch_time Integer
    0 ... 31536000
    默认值:2
    slow_query_log boolean
    on | off

    要详细了解慢查询日志,请参阅提示部分。

    sort_buffer_size integer
    32768 9223372036854775807
    source_verify_checksum boolean
    on | off
    默认值:off
    sql_mode string

    如需了解允许的值(包括 ANSI 等组合模式),请参阅 MySQL 文档中的 Server SQL 模式。不支持 NO_DIR_IN_CREATE

    Cloud SQL for MySQL 不支持将空值用于 sql_mode 标志。请将此标志设置为 NO_ENGINE_SUBSTITUTION 模式,而不是使用空值。

    sql_require_primary_key boolean
    on | off
    默认值:off
    sql_select_limit integer 0...18446744073709551615
    默认值:18446744073709551615

    要详细了解此标志,请参阅提示部分。

    stored_program_cache integer
    16 524288
    stored_program_definition_cache integer
    256 ... 524288
    默认值:256
    sync_binlog integer
    0 4294967295

    默认设置 1 允许在提交事务之前将二进制日志同步到磁盘。

    默认情况下,如果您提升启用了此标志的副本,则此标志会自动移除,导致提升的副本具有完整的耐用性。如需将此标志与提升的副本搭配使用,您可以在提升后将标志更新为副本。

    要详细了解此标志,请参阅提示部分。

    sync_master_info integer
    0 ... 4294967295
    默认值:10000
    sync_relay_log integer
    0 ... 4294967295
    默认值:10000
    sync_relay_log_info integer
    0 ... 4294967295
    默认值:10000
    sync_source_info integer
    0 ... 4294967295
    默认值:10000
    sysdate_is_now boolean
    on | off
    默认值:off
    table_definition_cache integer
    400 524288
    tablespace_definition_cache integer
    256 ... 524288
    默认值:256
    table_open_cache integer
    1 524288
    table_open_cache_instances integer
    1 64
    temptable_max_mmap integer
    0 ... 68719476736
    默认值:1073741824
    temptable_max_ram integer
    2097152 ... 68719476736
    默认值:1073741824
    thread_cache_size integer
    0 16384
    thread_stack integer
    131072 9223372036854775807
    tls_version String

    5.7 版到 8.0.27 版: TLSv1, TLSv1.1
    8.0.28 版或更高版本:TLSv1.2
    5.7 版:是

    8.0 版或更高版本:否
    tmp_table_size integer
    1024 67108864

    要详细了解此标志,请参阅提示部分。

    transaction_alloc_block_size integer
    1024 131072
    transaction_isolation enumeration
    READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE
    transaction_prealloc_size integer
    1024 131072
    transaction_write_set_extraction enumeration

    如需了解如何使用此标志及其可接受的值,请参阅配置并行复制

    unique_checks boolean
    on | off
    默认值:on

    要详细了解此标志,请参阅提示部分。

    updatable_views_with_limit integer
    0 1
    wait_timeout integer
    1 31536000
    windowing_use_high_precision boolean
    on | off
    默认值:on

    时区名称

    在此部分中,您将了解 Cloud SQL for MySQL 支持的时区名称。

    本部分中的表格显示以下内容:

    • 时区名称:Cloud SQL for MySQL 支持的名称。
    • STD:标准时间 (STD) 的时区偏移量。
    • DST:夏令时 (DST) 的时区偏移量。
    • 同义词名称:您可能想要使用,但不受 Cloud SQL for MySQL 支持的时区名称。如果出现这种情况,请使用相应的时区名称。
    时区名称 STD DST 同义词名称
    Africa/Cairo +02:00 +02:00 Egypt
    Africa/Casablanca +01:00 +00:00
    Africa/Harare +02:00 +02:00 Africa/Maputo
    Africa/Monrovia +00:00 +00:00
    Africa/Nairobi +03:00 +03:00 Africa/Addis_Ababa
    Africa/Asmera
    Africa/Dar_es_Salaam
    Africa/Djibouti
    Africa/Kampala
    Africa/Mogadishu
    Indian/Antananarivo
    Indian/Comoro
    Indian/Mayotte
    Africa/Tripoli +02:00 +02:00 利比亚
    Africa/Windhoek +02:00 +02:00
    America/Araguaina −03:00 −03:00
    America/Asuncion −04:00 −03:00
    America/Bogota −05:00 −05:00
    America/Buenos_Aires −03:00 −03:00 America/Argentina/Buenos_Aires
    America/Caracas −04:00 −04:00
    America/Chicago −06:00 −05:00
    America/Chihuahua −07:00 −06:00 America/Ojinaga
    America/Cuiaba −04:00 −04:00
    America/Denver −07:00 −06:00 America/Shiprock
    Navajo
    MST7MDT
    US/Mountain
    America/Detroit −05:00 −04:00
    America/Fortaleza −03:00 −03:00
    America/Guatemala −06:00 −06:00
    America/Halifax −04:00 −03:00 Canada/Atlantic
    America/Los_Angeles −08:00 −07:00
    America/Manaus −04:00 −04:00 Brazil/West
    America/Matamoros −06:00 −05:00
    America/Mexico_City −06:00 −05:00
    America/Monterrey −06:00 −05:00
    America/Montevideo −03:00 −03:00
    America/New_York −05:00 −04:00
    America/Phoenix −07:00 −07:00 US/Arizona
    MST
    America/Creston
    America/Santiago −04:00 −03:00 Chile/Continental
    America/Sao_Paolo −03:00 −03:00
    America/Tijuana −08:00 −07:00 Mexico/BajaNorte
    America/Ensenada
    America/Santa_Isabel
    Asia/Amman +02:00 +03:00
    Asia/Ashgabat +05:00 +05:00 Asia/Ashkhabad
    Asia/Baghdad +03:00 +03:00
    Asia/Baku +04:00 +04:00
    Asia/Bangkok +07:00 +07:00 Asia/Phnom_Penh
    Asia/Vientiane
    Asia/Beirut +02:00 +03:00
    Asia/Calcutta +05:30 +05:30 Asia/Kolkata
    Asia/Damascus +02:00 +03:00
    Asia/Dhaka +06:00 +06:00 Asia/Dacca
    Asia/Irkutsk +08:00 +08:00
    Asia/Jerusalem +02:00 +03:00 Asia/Tel_Aviv
    Israel
    Asia/Kabul +04:30 +04:30
    Asia/Karachi +05:00 +05:00
    Asia/Kathmandu +05:45 +05:45 Asia/Katmandu
    Asia/Kolkata +05:30 +05:30
    Asia/Krasnoyarsk +07:00 +07:00
    Asia/Magadan +11:00 +11:00
    Asia/Muscat +04:00 +04:00 Asia/Dubai
    Asia/Novosibirsk +07:00 +07:00
    Asia/Riyadh +03:00 +03:00 Asia/Kuwait
    Antarctica/Syowa
    Asia/Aden
    Asia/Seoul +09:00 +09:00 ROK
    Asia/Shanghai +08:00 +08:00 Asia/Chongqing
    Asia/Chungking
    Asia/Harbin
    PRC
    Asia/Singapore +08:00 +08:00 Singapore
    Asia/Taipei +08:00 +08:00 ROC
    Asia/Tehran +03:30 +04:30 Iran
    Asia/Tokyo +09:00 +09:00 Japan
    Asia/Ulaanbaatar +08:00 +08:00 Asia/Ulan_Bator
    Asia/Vladivostok +10:00 +10:00
    Asia/Yakutsk +09:00 +09:00
    Asia/Yerevan +04:00 +04:00
    Atlantic/Azores −01:00 +00:00
    Australia/Adelaide +09:30 +10:30 Australia/South
    Australia/Brisbane +10:00 +10:00 Australia/Queensland
    Australia/Darwin +09:30 +09:30 Australia/North
    Australia/Hobart +10:00 +11:00 Australia/Currie
    Australia/Tasmania
    Australia/Perth +08:00 +08:00 Australia/West
    Australia/Sydney +10:00 +11:00 Australia/NSW
    Australia/ACT
    Australia/Canberra
    Brazil/East −03:00 −03:00 America/Sao_Paulo
    Canada/Newfoundland −03:30 −02:30 America/St_Johns
    Canada/Saskatchewan −06:00 −06:00 America/Regina
    Canada/Yukon −07:00 −07:00 America/Whitehorse
    Europe/Amsterdam +01:00 +02:00
    Europe/Athens +02:00 +03:00
    Europe/Dublin +01:00 +00:00 Eire
    Europe/Helsinki +02:00 +03:00 Europe/Mariehamn
    Europe/Istanbul +03:00 +03:00 Turkey
    Asia/Istanbul
    Europe/Kaliningrad +02:00 +02:00
    Europe/Madrid +01:00 +02:00
    Europe/Moscow +03:00 +03:00 W-SU
    Europe/Paris +01:00 +02:00 MET
    CET
    Europe/Prague +01:00 +02:00 Europe/Bratislava
    Europe/Sarajevo +01:00 +02:00 Europe/Belgrade
    Europe/Ljubljana
    Europe/Podgorica
    Europe/Skopje
    Europe/Zagreb
    Pacific/Auckland +12:00 +13:00 NZ
    Antarctica/McMurdo
    Antarctica/South_Pole
    Pacific/Fiji +12:00 +13:00
    Pacific/Guam +10:00 +10:00 Pacific/Saipan
    Pacific/Honolulu −10:00 −10:00 US/Hawaii
    Pacific/Johnston
    HST
    Pacific/Samoa −11:00 −11:00 Pacific/Pago_Pago
    US/Samoa
    US/Alaska −09:00 −08:00 America/Anchorage
    America/Juneau
    America/Metlakatla
    America/Nome
    America/Sitka
    America/Yakutat
    US/Central −06:00 −05:00 America/Chicago
    US/Eastern −05:00 −04:00 America/New_York
    US/East-Indiana −05:00 −04:00 America/Indiana/Indianapolis
    America/Indianapolis
    America/Fort_Wayne
    US/Mountain −07:00 −06:00 America/Denver
    US/Pacific −08:00 −07:00 America/Los_Angeles
    UTC +00:00 +00:00 Etc/UTC
    Etc/UCT
    Etc/Universal
    Etc/Zulu

    Cloud SQL 中的时区表可能需要使用最新数据进行刷新。例如,某个国家/地区可能会从 DST 时区偏移量转换为 STD 偏移量,或者某个国家/地区可能会引入新的时区。

    对于 Cloud SQL 的每个关键服务代理 (CSA) 版本,时区表都会使用最新数据刷新。发生这种情况时,系统会在非维护窗口内刷新副本实例,然后在维护窗口内刷新主实例。

    您可以等到 CSA 版本的定期维护窗口,也可以执行自助服务维护以使用最新数据刷新时区表。如需详细了解如何查看可用的维护版本,请参阅确定目标维护版本

    有关使用标志的提示

    general_log、slow_query_log

    要使您的 generalslow query 日志可供使用,请启用相应的标志并将 log_output 标志设置为 FILE。这样您便可以使用 Google Cloud 控制台中的日志查看器阅读日志输出内容。请注意,您需要支付 Google Cloud Observability 日志记录费用。为了最大限度地降低实例存储费用,如果日志文件存在时间超过 24 小时(在该时间段内未进行任何更改)或大小大于 100MB,则实例磁盘上的 generalslow query 日志会被轮替。轮替后,系统会自动删除旧日志文件。

    如果 log_output 设置为 NONE,则您无法访问日志。如果将 log_output 设置为 TABLE,则日志输出将被放入 mysql 系统数据库的表中。它可能会占用大量磁盘空间。如果此表扩大,则可能会影响实例重启时间,或者导致实例脱离其服务等级协议 (SLA) 覆盖范围。因此,建议不要使用 TABLE 选项。此外,日志内容在 Logs Explorer 中不可用,且不会轮替。如果需要,您可以使用 API 截断日志表。如需了解详情,请参阅 instances.truncateLog 参考页面

    expire_logs_days、binlog_expire_logs_seconds
    如果您启用时间点恢复,二进制日志的到期时间将由事务日志保留期限和这些标志的值中的较小值决定。您可以使用这些标志来管理二进制日志在副本上存储的时长。如需了解详情,请参阅事务日志保留页面。
    innodb_buffer_pool_size

    innodb_buffer_pool_size 的值是缓冲池的大小(以字节为单位)。您无法为 RAM 小于 3840 MiB 的实例启用此标志。

    共享核心机器类型(f1_micro 和 g1_small)不可配置此标志。在 MySQL 5.6 上更改此标志需要重启。

    在 Cloud SQL 中,innodb_buffer_pool_size 标志的默认值、允许最小值和最大值取决于实例的内存。这些值可以粗略计算为实例 RAM 的百分比。默认情况下,此标志的值通常设置为接近最大允许值。最大允许分配百分比随实例大小而增加。最小允许的值通常约为实例的 RAM 的 20%。

    此标志的近似值

    实例 RAM 范围下限 %默认 %上限 %
    0 - 4.0GB RAM~34%
    4.0GB - 7.5GB~20%~34%~34%
    7.5GB - 12GB~20%~52%~52%
    12GB - 24GB~20%~67%~67%
    24GB 及以上~20%~72%~72%

    您的确切值可能会有所不同。如需计算实例的当前值,您可以运行查询:

      show global variables like 'innodb_buffer_pool_size';
      

    作为参考,下面为机器类型提供了最小允许值、默认值和最大允许值。

    机器类型 实例 RAM (GB) 下限 (GB)
    (占总数的百分比)
    默认 (GB)
    (占总数的百分比)
    上限 (GB)
    (占总数的百分比)
    db-f1-micro 0.6 - 0.053 -
    db-g1-small 1.7 - 0.625 -
    db-custom-1-3840 3.75 0.875
    (23%)
    1.375
    (37%)
    1.375
    (37%)
    db-custom-2-7680 7.5 1.5
    (20%)
    4
    (53%)
    4
    (53%)
    db-custom-4-15360 15 3
    (20%)
    10.5
    (70%)
    10.5
    (70%)
    db-custom-8-30720 30 6
    (20%)
    22
    (73%)
    22
    (73%)
    db-custom-16-61440 60 12
    (20%)
    44
    (73%)
    44
    (73%)
    db-custom-32-122880 120 24
    (20%)
    87
    (73%)
    87
    (73%)
    db-custom-64-245760 240 48
    (20%)
    173
    (72%)
    173
    (72%)
    db-custom-96-368640 360 72
    (20%)
    260
    (72%)
    260
    (72%)
    db-custom-2-13312 13 3
    (23%)
    9
    (69%)
    9
    (69%)
    db-custom-4-26624 26 6
    (23%)
    19
    (73%)
    19
    (73%)
    db-custom-8-53248 52 11
    (21%)
    38
    (73%)
    38
    (73%)
    db-custom-16-106496 104 21
    (20%)
    75
    (72%)
    75
    (72%)
    db-custom-32-212992 208 42
    (20%)
    150
    (72%)
    150
    (72%)
    db-custom-64-425984 416 84
    (20%)
    300
    (72%)
    300
    (72%)
    db-custom-96-638976 624 125
    (20%)
    450
    (72%)
    450
    (72%)

    innodb_file_per_table

    对于所有 MySQL 5.6 版及更高版本,默认值为 ON

    innodb_flush_log_at_trx_commit、sync_binlog
    为了实现完全 ACID 合规性,并在复制设置中保持耐用性和一致性,必须将 innodb_flush_log_at_trx_commitsync_binlog 标志设置为默认值 1。如果更改默认值,则耐用性可能会降低,这可能会导致主实例与副本之间不一致。因此,实例会失去服务等级协议 (SLA) 覆盖范围。此外,还可能发生以下任何情况:
    • 数据在某些情况下丢失,例如虚拟机崩溃或区域高可用性实例故障切换
    • 二进制日志和 InnoDB 数据文件中不同步的数据
    • PITR 数据丢失或失败
    • 主实例与其副本之间的数据不一致
    • 复制中断

    innodb_flush_log_at_trx_commitsync_binlog 标志的值设置为主实例、独立实例和高可用性实例的非默认值会导致耐用性降低。

    如果您需要更高的读取副本性能,我们建议将 innodb_flush_log_at_trx_commit 值设置为 2。 Cloud SQL 不支持将此标志的值设置为 0。如果将此标志的值设置为 2,则必须对副本停用二进制日志,或者将 sync_binlog 设置为除 1 以外的值以提高性能。

    在备份时,Cloud SQL 可能会暂时将 innodb_flush_log_at_trx_commitsync_binlog 标志值更改为默认值。这可能会导致备份时性能降低。为了避免影响您的实例,您可以在实例使用率较低时更改备份时段。如需了解详情,请参阅创建和管理按需备份与自动备份

    innodb_flush_log_at_timeout

    innodb_flush_log_at_timeout 允许您修改页面刷新的频率,从而避免影响二进制日志组提交的性能。默认设置是每秒一次。

    Cloud SQL 扩展了此标志,以支持指定以微秒为单位的时间段。

    示例:

    • 0.001(用于指定 1 毫秒)
    • 0.0001(用于指定 100 微秒)
    • 12.5(用于指定 12.5 秒)
    • 12.005(用于指定 12.005 秒)
    • 0.005100(用于指定 0.005100 秒)

    对于某些工作负载,由于事务可能丢失,使用整秒粒度来刷新页面可能是不可接受的。相反,您可以使用微秒粒度刷新页面以保持性能,而不会显著影响耐用性。

    只有在 innodb_flush_log_at_trx_commit 耐用性标志设置为 2 时,innodb_flush_log_at_timeout 标志的微秒时间段才适用。

    刷新网页的频率可能高于或低于为 innodb_flush_log_at_timeout 指定的值,并且该值不是上限。

    max_heap_table_size、tmp_table_size

    如果 tmp_table_sizemax_heap_table_size 的值对于实例处理的并发查询数来说设置得过高,可能会耗尽可用的实例内存。内存耗尽会导致实例崩溃和重启。

    如需详细了解如何使用这些标志,请参阅 MySQL 如何使用内部临时表MEMORY 存储引擎

    performance_schema

    您无法对 RAM 小于 15360 MiB 的实例启用此标志。如果启用此标志,则无法将机器类型更改为不支持该标志的大小;您必须先停用此标志。

    event_scheduler
    MySQL 事件(也称为计划事件)是您可以安排的任务。计划事件是一条或多条 SQL 语句组,这些语句设置为按一个或多个指定的时间间隔执行。MySQL 5.7 的默认值为 OFF,MySQL 8.0 的默认值为 ON。如需详细了解 event_scheduler 标志,请参阅 event_scheduler。 如果将读取副本的 event_scheduler 标志设置为 ON,则根据事件中定义的语句类型,可能会导致错误:
    • 如果您的计划事件是读取副本上的 write 事件,则会导致错误,因为读取副本是只读的。如需了解详情,请参阅读取副本
    • 如果计划事件包含停止操作(例如 kill),则 event_scheduler 会将它应用于副本。这会停止复制并删除副本。
    为避免此类错误,请在创建副本时将 event_scheduler 标志设置为 OFF

    如需详细了解如何启用或停用 event_scheduler,请参阅配置数据库标志

    replica_skip_errors、slave_skip_errors
    设置 replica_skip_errorsslave_skip_errors 标志可能会导致复制问题。通常,如果在执行语句时发生错误,则复制会停止。如果使用此标志,则系统会跳过错误并继续复制,从而导致主实例和副本不一致。这也更难排查复制问题。

    Cloud SQL 建议仅在必要时使用此标志。如果您遇到复制错误,请参阅“排查 Cloud SQL 问题:复制”,详细了解如何解决此问题。

    character_set_client
    character_set_connection
    character_set_results
    collation_connection
    innodb_buffer_pool_dump_now
    innodb_buffer_pool_load_abort
    innodb_buffer_pool_load_now
    innodb_ft_aux_table
    foreign_key_checks
    sql_select_limit
    unique_checks
    您无法直接在 Google Cloud 控制台中或使用 gcloud CLI 选择这些标志。 如需使用这些标志,请使用以下命令:

    SET GLOBAL FLAG_NAME=FLAG_VALUE
    

    使用 SET GLOBAL 命令需要 CLOUDSQL_SPECIAL_SYSEM_VARIABLES_ADMIN 权限,该权限会被授予 cloudsqlsuperuser 角色。

    如需详细了解如何向特定用户授予特殊访问权限,请参阅 MySQL 用户简介。这些标志不会持久保留。重新创建或重启 Cloud SQL 实例后,标志设置会重置为默认值。

    binlog_order_commits

    binlog_order_commits 标志的默认值为 ON。 Cloud SQL 建议不要更改此标志的默认值。如果将默认值更改为 OFF,则同一二进制日志组中事务的提交顺序将与二进制日志中写入的顺序不同。这会影响以下以二进制日志顺序执行事务的操作:

    • 复制:可能导致源与副本之间的数据不一致
    • 时间点恢复:可能会导致 PITR 恢复状态与历史状态之间的数据不一致

    optimizer_switch、optimizer_trace、optimizer_trace_features

    优化器标志包含逗号分隔值。您可以使用控制台或 gcloud 设置这些标志。如需详细了解如何使用控制台设置此标志,请参阅配置数据库标志。如果使用 gcloud,您可以通过两种不同的方式指定这些标志的值:

    如需在一条命令中设置多个优化器子标志,请使用逗号分隔符分隔各个标志名称。如果您使用 gcloud 命令设置单个子标志值,则该命令会覆盖所有之前设置的子标志。例如,如果您运行以下命令,则 batched_key_access 子标志的预期值设置为 on,并将 optimizer_flags 的所有其他子标志设置为其默认值。
    gcloud sql instances patch my-instance --database-flags=^~^optimizer_switch=batched_key_access=on
    
    如果您运行以下命令,block_nested_loop 子标志设置为 on 以及 optimize_switch 的所有其他子标志将被覆盖并设置为默认值。
    gcloud sql instances patch my-instance --database-flags=^~^optimizer_switch=block_nested_loop=on
    
    这包括由上一个命令设置为 onbatched_key_access。要保留先前设置的所有子标志并添加新标志,则必须在添加新的子标志时添加所有要设置子标志的值。

    Cloud SQL 中的系统标志已更改

    支持的标志部分中未列出的所有其他数据库系统标志称为代管式标志。对于某些代管式标志,Cloud SQL 将标志设置为默认设置以外的值,以确保 Cloud SQL 实例可靠运行。您无法更改这些系统标志上的值。

    下面列出了采用非默认设置的代管式标记。

    变量名称 在 Cloud SQL 中的设置。 备注
    binlog_format ROW 仅在 MySQL 5.6 中不同
    binlog_error_action ABORT_SERVER 仅在 MySQL 5.6 中不同
    innodb_doublewrite_pages 64 适用于 MySQL 8.0.26 及更高版本
    innodb_file_format Barracuda 仅在 MySQL 5.6 中不同
    innodb_flush_method O_DIRECT
    memlock
    skip_name_resolve ON
    relay_log_info_repository TABLE
    relay_log_recovery 已启用
    master_info_repository TABLE
    rpl_semi_sync_master_enabled 1
    rpl_semi_sync_master_timeout 3000
    admin_address 127.0.0.1 仅在 MySQL 8.0 中不同
    create_admin_listener_thread ON
    port-open-timeout 120 仅在 MySQL 8.0 中不同
    partial_revokes 开启 仅限 MySQL 8.0。如需详细了解此标志,请参阅 MySQL 8.0 中的部分撤消系统标志

    MySQL 8.0 中的 partial_revokes 系统标志

    使用 partial_revokes 标志,您可以限制用户对数据库架构的访问权限。在 Cloud SQL for MySQL 8.0 版中,partial_revokes 标志设置为 ON。这限制了在 MySQL 8.0 中授予或撤消对数据库架构的用户特权时使用通配符。更新 GRANT 语句以使用数据库架构的全名而不是通配符。

    例如,如果使用带有 %\ 通配符的以下命令来向 MySQL 5.7 中的用户授予特权,则该用户将获得以 _foobar 结尾的所有数据库的特权。

    GRANT ALL PRIVILEGES ON `%\_foobar`.*  TO  'testuser'@'%';
    

    但是,在 MySQL 8.0 中,用户只能访问与 %\_foobar 完全匹配的数据库。

    您可以通过两种不同的方法授予对 MySQL 8.0 中多个数据库的访问权限。

    1. 您可以使用完整数据库名称向特定数据库授予权限,如以下命令所示:

        grant select on test1_foobar.* to 'testuser'@'%';
        grant select on test2_foobar.* to 'testuser'@'%';
        grant select on test3_foobar.* to 'testuser'@'%';
      
    2. 借助 partial_revokes,您可以使用 grantrevoke 命令授予所有数据库架构的用户特权,同时限制对一些数据库架构的访问。

        grant select on *.* to 'testuser'@'%';
        revoke select on test3_foobar.* from 'testuser'@'%';
      

      此命令会授予对所有数据库架构的访问权限,同时限制对 test3_foobar.* 的访问权限。

    复制过滤条件

    您只能对 Cloud SQL 副本设置复制过滤条件。每个复制过滤条件设置为多个数据库的单个标志,其中每个数据库名称以逗号分隔。您可以使用控制台或以下命令在 Cloud SQL 副本上设置复制过滤条件:

    gcloud sql instances patch REPLICA_NAME --database-flags=^~^REPLICATION_FILTER_NAME=DATABASE_NAME1,DATABASE_NAME, etc
    

    复制过滤条件不支持包含逗号值的数据库名称。对于以逗号分隔的数据库标志,上述命令中的 ^~^ 值是必需的。

    设置复制过滤条件标志时,请注意以下几点:

    • 如果副本健康状况不佳,则由复制过滤条件过滤的数据可能会出现在副本上,因为 Cloud SQL 会使用主实例中的源数据来重新构建实例副本。
    • 您无法在 mysql 架构上设置复制过滤条件。
    • 复制过滤条件规则不适用于无服务器导出。

    索引顾问标志

    下面列出了 Cloud SQL for MySQL 用于启用和管理索引顾问专用功能的数据库标志。

    标志名称 类型
    可接受值及备注
    是否需要
    重启?
    cloudsql_index_advisor boolean
    on | off
    默认值:off
    cloudsql_index_advisor_auto_advisor_schedule string
    默认值:00:00
    cloudsql_index_advisor_run_at_timestamp Datetime
    默认值:00:00:00

    别名标志

    以下列表包含 Cloud SQL for MySQL 8.0.26 及更高版本更改的标志名称。

    已弃用的标志名称 新标志名称
    log_slow_slave_statements log_slow_replica_statements
    master_verify_checksum source_verify_checksum
    slave_checkpoint_group replica_checkpoint_group
    slave_checkpoint_period replica_checkpoint_period
    slave_compressed_protocol replica_compressed_protocol
    slave_net_timeout replica_net_timeout
    slave_parallel_type replica_parallel_type
    slave_parallel_workers replica_parallel_workers
    slave_pending_jobs_size_max replica_pending_jobs_size_max
    slave_preserve_commit_order replica_preserve_commit_order
    slave_skip_errors replica_skip_errors
    slave_sql_verify_checksum replica_sql_verify_checksum
    slave_transaction_retries replica_transaction_retries
    slave_type_conversions replica_type_conversions
    sync_master_info sync_source_info

    如果您的 Cloud SQL 实例使用的是已弃用的标志名称,请修改您的 Cloud SQL 实例,删除已弃用的标志名称,然后将新标志添加到实例中。如需了解详情,请参阅设置数据库标志

    问题排查

    问题 问题排查
    启用标志后,实例会在错误和崩溃之间循环。 请与客户服务联系,请求移除标志,然后执行 hard drain。这会强制实例在使用新配置(没有不需要的标志或设置)的其他主机上重启。
    尝试设置标志时,您看到错误消息 Bad syntax for dict arg与 gcloud 命令搭配使用时,复杂的参数值(例如以英文逗号分隔的列表)需要特殊处理。

    后续步骤