本页面介绍如何为 Cloud SQL 配置数据库标志,并列出了可以为实例设置的标志。您可以将数据库标志用于许多操作,包括调整 MySQL 参数、调整选项以及配置和优化实例。
在某些情况下,设置一个标志时,可能需要设置另一个标志才能完全启用所需功能。例如,如需启用慢查询日志记录,您必须将 slow_query_log
标志设置为 on
并将 log_output
标志设置为 FILE
,才能使用 Google Cloud Console 日志浏览器来阅读日志。
当您设置、移除或修改数据库实例的标志时,该数据库可能会重启。除非您主动移除,否则实例的此标志值会一直保留。如果实例是副本的来源,并且实例已经重启,那么系统还会重启副本以与实例的当前配置保持一致。
配置数据库标志
设置数据库标志
控制台
- 在 Google Cloud Console 中,创建新的 Cloud Console 项目,或者选择项目名称以打开现有项目。
- 打开实例,然后点击修改。
- 向下滚动至标志部分。
- 要在实例上设置先前未设置的标志,请点击添加一项,从下拉菜单中选择该标志,然后设置其值。
- 点击保存以保存更改。
- 在“概览”页的标志下确认更改。
gcloud
修改实例:
gcloud sql instances patch [INSTANCE_NAME] --database-flags=[FLAG1=VALUE1,FLAG2=VALUE2]
此命令将覆盖之前设置的所有数据库标志。如需保留这些标志并添加新标志,请为您要在实例上设置的所有标志添加值;任何未明确添加的标志都会设置为默认值。对于不带值的标志,请指定标志名称并后接一个等号(“=”)。
例如,如需设置 general_log
、skip_show_database
和 wait_timeout
标志,您可以使用以下命令:
gcloud sql instances patch [INSTANCE_NAME] \ --database-flags=general_log=on,skip_show_database=on,wait_timeout=200000
Terraform
如需添加数据库标志,请使用 Terraform 资源。
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
命令会使用请求中指定的标志覆盖现有标志。
将所有标志恢复为其默认值
控制台
- 在 Google Cloud Console 中,创建新的 Cloud Console 项目,或者选择项目名称以打开现有项目。
- 打开实例,然后点击修改。
- 打开数据库标志部分。
- 点击显示的所有标志旁的 X。
- 点击保存以保存更改。
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 实例设置的标志:
控制台
- 在 Google Cloud Console 中,创建新的 Cloud Console 项目,或者选择项目名称以打开现有项目。
- 选择实例,打开其实例概览页面。
数据库标志部分列出了已设置的数据库标志。
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 | I | L | M | N | O | P | Q | R | S | T | U | W
Cloud SQL 标志 | 类型 可接受值及备注 |
是否需要 重启? |
---|---|---|
activate_all_roles_on_login |
boolean on | off
默认值: off
|
否 |
auto_increment_increment | integer 1 至 65535 |
否 |
auto_increment_offset | integer 1 至 65535 |
否 |
binlog_cache_size | integer 4096 至 9223372036854775807 |
否 |
binlog_expire_log_seconds | integer 0 或 86400 (1 day) ... 4294967295 (max value) 默认值为 2592000,相当于 30 天。 要详细了解此标志,请参阅提示部分。 |
否 |
binlog_group_commit_sync_delay | 0 ... 1000000
默认值为 0 |
否 |
binlog_group_commit_sync_no_delay_count | 0 ... 1000000
默认值为 0 |
否 |
binlog_row_image | enumeration full (默认)、minimal 或 noblob |
否 |
binlog_stmt_cache_size | 4096 至 9223372036854775807 |
否 |
binlog_transaction_dependency_history_size | integer
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
binlog_transaction_dependency_tracking | enumeration
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
character_set_server | string utf8 或 utf8mb4(推荐) |
是 |
default_password_lifetime | integer 0...65535
默认值: 0
|
否 |
default_time_zone | string 将值指定为时区偏移量,范围为 -12:59 到 +13:00 。必须添加前导零。
例如,伦敦采用世界协调时间 (UTC) 时区,因此此标志支持的值为 +00:00。Cloud SQL 不支持已命名的区域,例如“欧洲/伦敦”。 |
是 |
disconnect_on_expired_password | boolean on | off
默认值: on
|
是 |
eq_range_index_dive_limit | integer 0 至 2147483647 |
否 |
event_scheduler | boolean on | off
如果您使用的是 Event Scheduler,请将实例的激活政策配置为 ALWAYS,以确保预定事件正常运行。 |
否 |
expire_log_days | integer 0 ... 99 默认值为 0,表示不可自动移除。 要详细了解此标志,请参阅提示部分。 |
否 |
explicit_defaults_for_timestamp | boolean on | off |
是 |
ft_max_word_len | integer 10 至 252 |
是 |
ft_min_word_len | integer 1 至 16 |
是 |
ft_query_expansion_limit | integer 0 至 1000 |
是 |
general_log | boolean on | off
要详细了解常规日志,请参阅提示部分。 |
否 |
generated_random_password_length | integer 5-255
默认值: 20
|
否 |
group_concat_max_len | integer 4 至 17179869184 |
否 |
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_autoinc_lock_mode | integer 0 至 2 |
是 |
innodb_buffer_pool_size | integer
为 MySQL 5.6 设置此标志需要重启。要详细了解此标志,请参阅提示部分。 | 否 |
innodb_change_buffer_max_size | integer 0 至 50 |
否 |
innodb_concurrency_tickets | integer 1 至 4294967295 |
否 |
innodb_file_per_table | boolean on | off
要详细了解此标志,请参阅提示部分。 |
否 |
innodb_fill_factor | integer 10 至 100 |
否 |
innodb_flush_log_at_trx_commit | integer 1, 2 默认值: 1 。要详细了解此标志,请参阅提示部分。 |
否 |
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_large_prefix | boolean on | off
仅受 MySQL 5.6 支持。 |
否 |
innodb_lock_wait_timeout | integer 1 至 1073741824 |
否 |
innodb_log_buffer_size | integer 262144 至 4294967295 |
是 |
innodb_log_file_size | integer MySQL 5.6: 1048576 至 274877906944 MySQL 5.7: 4194304 至 274877906944
|
是 |
innodb_lru_scan_depth | integer 100 至 9223372036854775807 |
否 |
innodb_old_blocks_pct | integer 5 至 95 |
否 |
innodb_old_blocks_time | integer 0 至 4294967295 |
否 |
innodb_online_alter_log_max_size | integer 65536 至 9223372036854775807 |
否 |
innodb_optimize_fulltext_only | boolean on | off |
否 |
innodb_print_all_deadlocks | boolean on | off |
否 |
innodb_purge_threads | 1 ... 32
默认值为 1。 |
是 |
innodb_random_read_ahead | boolean on | off |
否 |
innodb_read_ahead_threshold | integer 0 至 64 |
否 |
innodb_read_io_threads | integer 1 至 64
|
是 |
innodb_replication_delay | integer 0 至 4294967295 |
否 |
innodb_rollback_on_timeout | boolean on | off |
是 |
innodb_rollback_segments | integer 1 至 128 |
否 |
innodb_sort_buffer_size | integer 65536 至 67108864 |
是 |
innodb_stats_auto_recalc | boolean on | 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
默认值为 1。 |
是 |
innodb_thread_concurrency | integer 0 至 1000 |
否 |
innodb_thread_sleep_delay | integer 0 至 1000000 |
否 |
innodb_write_io_threads | integer 1 至 64 |
是 |
interactive_timeout | integer 1 至 31536000 |
否 |
internal_tmp_mem_storage_engine | enumeration MEMORY 、TempTable 此标志仅用于 MySQL 8.0。 |
否 |
join_buffer_size | integer 128 至 9223372036854775807 |
否 |
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_queries_not_using_indexes | boolean on | off |
否 |
log_throttle_queries_not_using_indexes | integer 0 至 9223372036854775807 |
否 |
long_query_time | float 0 至 30000000
如果需要,Cloud SQL 可为此标志设置一个小于 1 的值。 如果还启用了 |
否 |
lower_case_table_names | integer 0 或 1
大多数情况下,使用默认值 0,这会使表和数据库的名称区分大小写。如果需要更改此标志的值,请确保您了解此更改对现有表和数据库产生的影响。 |
是 |
mandatory_roles | string role name
默认值: empty string
|
否 |
max_allowed_packet | integer 16384 至 1073741824
如果 sql_mode=TRADITIONAL 或 sql_mode=STRICT_ALL_TABLES,则此值必须为 1024 的倍数。 |
否 |
max_binlog_size | integer 4096 至 1073741824 |
否 |
max_connections | integer 14 ... 262143
|
否 |
max_digest_length | integer 0 至 1048576 |
是 |
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 |
否 |
net_read_timeout | integer 30 至 4294967295 |
否 |
net_retry_count | integer 10 至 4294967295 |
否 |
net_write_timeout | integer 60 至 4294967295 |
否 |
optimizer_prune_level | integer 0 至 1 |
否 |
optimizer_search_depth | integer 0 至 62 |
否 |
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
默认: 默认: 如需详细了解 performance_schema 标志,请参阅提示部分。 |
是 |
performance_schema_accounts_size | integer -1 至 1048576
如需详细了解 performance_schema 标志,请参阅提示部分。 |
是 |
performance_schema_digests_size | integer -1 至 1048576
如需详细了解 performance_schema 标志,请参阅提示部分。 |
是 |
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 -1 至 1048576
要详细了解 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_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 -1 至 1048576
要详细了解 performance_schema 标志,请参阅提示部分。 |
是 |
performance_schema_max_sql_text_length | integer 0 至 1048576
要详细了解 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 标志,请参阅提示部分。 |
是 |
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 |
否 |
show_compatibility_56 | boolean on | off
仅受 MySQL 5.7 支持。 |
否 |
skip_show_database | flag on | off |
是 |
slave_parallel_type | enumeration
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
slave_parallel_workers | integer
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
slave_preserve_commit_order | boolean
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
slave_pending_jobs_size_max | integer
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
slow_query_log | boolean on | off 要详细了解慢查询日志,请参阅提示部分。 |
否 |
sort_buffer_size | integer 32768 至 9223372036854775807 |
否 |
sql_mode | string
如需了解允许的值(包括 Cloud SQL for MySQL 不支持将空值用于 |
否 |
sql_safe_updates | boolean on | off
默认: off
如需详细了解 sql_safe_update 标志,请参阅提示部分。 |
否 |
stored_program_cache | integer 16 至 524288 |
否 |
sync_binlog | integer 0 至 4294967295
仅 MySQL 5.7 和 8.0 中的读取副本和外部服务器副本支持。 默认设置 1 允许在提交事务之前将二进制日志同步到磁盘。 主实例或旧版高可用性故障切换副本不支持此标志。如果提升使用此标志的副本,则此标志会被移除。 |
否 |
table_definition_cache | integer 400 至 524288 |
否 |
table_open_cache | integer 1 至 524288 |
否 |
table_open_cache_instances | integer 1 至 64 |
是 |
thread_cache_size | integer 0 至 16384 |
否 |
thread_stack | integer 131072 至 9223372036854775807 |
是 |
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
如需了解如何使用此标志及其可接受的值,请参阅配置并行复制。 |
否 |
updatable_views_with_limit | integer 0 至 1 |
否 |
wait_timeout | integer 1 至 31536000 |
否 |
有关使用标志的提示
- general_log、slow_query_log
-
要使您的
general
或slow query
日志可供使用,请启用相应的标志并将log_output
标志设置为FILE
。这样您便可以使用 Google Cloud Console 中的日志查看器阅读日志输出内容。请注意,您需要支付 Google Cloud 的运维套件日志记录费用。 为了最大限度地降低实例存储费用,如果日志文件存在时间超过 24 小时(在该时间段内未进行任何更改)或大小大于 100MB,则实例磁盘上的general
和slow query
日志会被轮替。轮替后,系统会自动删除旧日志文件。如果
log_output
设置为NONE
,则您无法访问日志。如果将log_output
设置为TABLE
,则日志输出将被放入 mysql 系统数据库的表中。它可能会占用大量磁盘空间。如果此表扩大,则可能会影响实例重启时间,或者导致实例脱离其服务等级协议 (SLA) 覆盖范围。因此,建议不要使用TABLE
选项。此外,日志内容在日志浏览器中不可用,且不会轮替。如果需要,您可以使用 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%)
对于所有 MySQL 5.6 版及更高版本,默认值为 ON
。
sync_binlog
设置为 1 以外的值。
您只能为读取副本和外部服务器副本启用此标志。对于外部服务器副本,必须将此标志设置为默认值 1,以实现完全 ACID 合规性。您无法为主实例或故障切换副本启用此标志。
如果 tmp_table_size
和 max_heap_table_size
的值对于实例处理的并发查询数来说设置得过高,可能会耗尽可用的实例内存。内存耗尽会导致实例崩溃和重启。
如需详细了解如何使用这些标志,请参阅 MySQL 如何使用内部临时表和 MEMORY 存储引擎。
您无法对 RAM 小于 15360 MiB 的实例启用此标志。如果启用此标志,则无法将机器类型更改为不支持该标志的大小;您必须先停用此标志。
如果启用了此变量,WHERE
或 LIMIT
子句中不使用键的 UPDATE
或 DELETE
语句会产生错误。因此,您可以捕获那些未正确使用键并可能会更改或删除大量行的 UPDATE
和 DELETE
语句。默认值为 OFF。
对于 mysql 客户端,您可以使用 --safe-updates 选项来启用 sql_safe_updates
。如需了解详情,请参阅使用 Safe-Updates 模式 (--safe-updates
)。
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 | |||||||||||||||
innodb_flush_neighbors | 0(在 MySQL 5.6 中)和 2(在 MySQL 5.7 和 8.0 中) | |||||||||||||||
innodb_io_capacity | 5000 | |||||||||||||||
innodb_buffer_pool_instances |
|
|||||||||||||||
memlock | 是 | |||||||||||||||
skip_name_resolve | ON | |||||||||||||||
relay_log_info_repository | TABLE | |||||||||||||||
relay_log_recovery | ON | |||||||||||||||
slave_net_timeout | 30 | |||||||||||||||
master_info_repository | TABLE | |||||||||||||||
rpl_semi_sync_master_enabled | 1 | |||||||||||||||
rpl_semi_sync_master_timeout | 3000 | |||||||||||||||
innodb_page_cleaners | 8 | 仅在 MySQL 5.7、8.0 中不同 | ||||||||||||||
admin_address | 127.0.0.1 | 仅在 MySQL 8.0 中不同 | ||||||||||||||
create_admin_listener_thread | ON | |||||||||||||||
port-open-timeout | 120 | 仅在 MySQL 8.0 中不同 | ||||||||||||||
innodb_io_capacity_max | 10000 |
问题排查
问题 | 问题排查 |
---|---|
启用标志后,实例会在错误和崩溃之间循环。 | 请与客户服务联系,请求移除标志,然后执行 hard drain 。这会强制实例在使用新配置(没有不需要的标志或设置)的其他主机上重启。 |
尝试设置标志时,您看到错误消息 Bad syntax for dict arg 。 | 与 gcloud 命令搭配使用时,复杂的参数值(例如以英文逗号分隔的列表)需要特殊处理。 |
时区不会自动更改。 | Cloud SQL for MySQL 不支持自动更改时区,必须手动更改,并且必须通过时区偏移值(而不是字符串)进行更改。 修改实例以更改 Europe/London 采用世界协调时间 (UTC) 时区,这是 default_time_zone 标志支持的值 +00:00 。 |
后续步骤
- 详细了解 MySQL 系统变量。
- 详细了解操作指南。