使用ClickHouse的MaterializeMySQL,将mysql某个库或某张表导入到ck中,需要保证MySQL的配置大致如下:
1 2 3 4 5 6
| default_authentication_plugin = mysql_native_password gtid_mode = ON enforce_gtid_consistency = ON
server_id = 1 log_bin = ON
|
可以 SHOW VARIABLES LIKE 'default_authentication_plugin';查看默认值
除了server_id,其他几个的默认值都符合
1 2 3 4 5 6 7 8 9
| ### server-id在MySQL配置文件(my.cnf)中的作用
1. **标识唯一性:** `server-id`在MySQL主从复制中扮演关键角色,用于区分不同的服务器。设置唯一的`server-id`是确保主从复制正常运作的必要步骤[[2](https://blog.csdn.net/weixin_31642733/article/details/113263071)][[8](https://blog.51cto.com/u_16099270/7179221)]。
2. **用于同步数据:** `server-id`用于标识数据同步的来源,记录语句最初从哪个服务器写入,确保数据同步的正确性[[3](https://blog.csdn.net/jh993627471/article/details/79177896)]。
3. **避免循环与冲突:** 在复制结构中,`server-id`用于避免SQL语句的无限循环和冲突,确保复制结构的稳定性和一致性[[6](https://codeantenna.com/a/NyD9CeEHVB)]。
设置正确的`server-id`是确保MySQL主从复制工作正常的关键,确保每个服务器的ID都是唯一的。
|
参考:
MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下;
在Linux下叫my.cnf,该文件位于/etc/my.cnf。
可以查找下:find / -name my.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
| auto_increment_increment=1 auto_increment_offset=1 automatic_sp_privileges=ON avoid_temporal_upgrade=OFF back_log=3000 binlog_cache_size=2097152 binlog_checksum=CRC32 binlog_format=ROW binlog_order_commits=ON binlog_row_image=FULL binlog_rows_query_log_events=OFF binlog_stmt_cache_size=32768 block_encryption_mode=aes-128-ecb bulk_insert_buffer_size=8388608 cdb_enable_offset_pushdown=OFF cdb_kill_idle_trans_timeout=0 cdb_kill_user_extra=root@% cdb_more_gtid_feature_supported=OFF cdb_optimize_large_trans_binlog=OFF character_set_filesystem=binary character_set_server=utf8 collation_server=utf8_general_ci concurrent_insert=AUTO connect_timeout=10 default_password_lifetime=0 default_storage_engine=InnoDB default_week_format=0 delay_key_write=ON delayed_insert_limit=100 delayed_insert_timeout=300 delayed_queue_size=1000 disconnect_on_expired_password=ON div_precision_increment=4 end_markers_in_json=OFF eq_range_index_dive_limit=200 event_scheduler=OFF explicit_defaults_for_timestamp=OFF flush_time=0 ft_max_word_len=84 ft_min_word_len=4 ft_query_expansion_limit=20 group_concat_max_len=1024 host_cache_size=644 init_connect= innodb_adaptive_flushing=ON innodb_adaptive_flushing_lwm=10 innodb_adaptive_hash_index=OFF innodb_adaptive_max_sleep_delay=150000 innodb_alter_table_default_algorithm=inplace innodb_async_truncate_size=128 innodb_autoextend_increment=64 innodb_autoinc_lock_mode=2 innodb_buffer_pool_dump_at_shutdown=ON innodb_buffer_pool_dump_pct=25 innodb_buffer_pool_instances=8 innodb_buffer_pool_load_at_startup=ON innodb_buffer_pool_size=11811160064 innodb_change_buffer_max_size=25 innodb_change_buffering=all innodb_checksum_algorithm=crc32 innodb_cmp_per_index_enabled=OFF innodb_commit_concurrency=0 innodb_compression_failure_threshold_pct=5 innodb_compression_level=6 innodb_compression_pad_pct_max=50 innodb_concurrency_tickets=5000 innodb_deadlock_detect=ON innodb_default_row_format=dynamic innodb_disable_sort_file_cache=OFF innodb_fast_ahi_cleanup_for_drop_table=OFF innodb_fast_ddl=OFF innodb_flush_log_at_trx_commit=1 innodb_flush_method=O_DIRECT innodb_flush_neighbors=0 innodb_flush_sync=ON innodb_ft_cache_size=8000000 innodb_ft_enable_diag_print=OFF innodb_ft_enable_stopword=ON innodb_ft_max_token_size=84 innodb_ft_min_token_size=3 innodb_ft_num_word_optimize=2000 innodb_ft_result_cache_limit=2000000000 innodb_ft_server_stopword_table=NULL innodb_ft_sort_pll_degree=2 innodb_ft_total_cache_size=640000000 innodb_ft_user_stopword_table=NULL innodb_io_capacity=20000 innodb_io_capacity_max=40000 innodb_large_prefix=ON innodb_lock_wait_timeout=50 innodb_log_checksums=ON innodb_log_compressed_pages=ON innodb_lru_scan_depth=1024 innodb_max_dirty_pages_pct=75.000000 innodb_max_dirty_pages_pct_lwm=0.000000 innodb_max_purge_lag=0 innodb_max_purge_lag_delay=0 innodb_max_undo_log_size=1073741824 innodb_monitor_disable=ALL innodb_monitor_enable=ALL innodb_old_blocks_pct=37 innodb_old_blocks_time=1000 innodb_online_alter_log_max_size=134217728 innodb_optimize_fulltext_only=OFF innodb_page_cleaners=4 innodb_print_all_deadlocks=ON innodb_purge_batch_size=300 innodb_purge_rseg_truncate_frequency=128 innodb_purge_threads=4 innodb_random_read_ahead=OFF innodb_read_ahead_threshold=56 innodb_read_io_threads=4 innodb_rollback_on_timeout=OFF innodb_rollback_segments=128 innodb_sort_buffer_size=1048576 innodb_spin_wait_delay=6 innodb_stats_auto_recalc=ON innodb_stats_method=nulls_equal innodb_stats_on_metadata=OFF innodb_stats_persistent=ON innodb_stats_persistent_sample_pages=20 innodb_stats_transient_sample_pages=8 innodb_status_output=OFF innodb_status_output_locks=OFF innodb_strict_mode=ON innodb_sync_array_size=1 innodb_sync_spin_loops=30 innodb_table_drop_mode=sync_drop innodb_table_locks=ON innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:1048576M innodb_thread_concurrency=0 innodb_undo_log_truncate=OFF innodb_write_io_threads=4 interactive_timeout=7200 join_buffer_size=262144 key_cache_age_threshold=300 key_cache_block_size=1024 key_cache_division_limit=100 lc_time_names=en_US local_infile=OFF lock_wait_timeout=31536000 log_output=FILE log_queries_not_using_indexes=OFF log_slow_admin_statements=OFF log_throttle_queries_not_using_indexes=0 log_timestamps=SYSTEM log_warnings=2 long_query_time=1.000000 low_priority_updates=OFF lower_case_table_names=1 master_verify_checksum=OFF max_allowed_packet=1073741824 max_connect_errors=999999999 max_connections=4500 max_error_count=64 max_execution_time=0 max_heap_table_size=67108864 max_length_for_sort_data=1024 max_points_in_geometry=65536 max_prepared_stmt_count=16382 max_sort_length=1024 max_sp_recursion_depth=0 max_user_connections=0 metadata_locks_cache_size=1024 min_examined_row_limit=0 myisam_sort_buffer_size=8388608 mysql_native_password_proxy_users=OFF net_buffer_length=16384 net_read_timeout=30 net_retry_count=10 net_write_timeout=60 ngram_token_size=2 optimizer_prune_level=1 optimizer_search_depth=62 optimizer_switch=index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on,prefer_ordering_index=on optimizer_trace_limit=1 optimizer_trace_max_mem_size=16384 optimizer_trace_offset=-1 performance_schema=OFF preload_buffer_size=32768 query_alloc_block_size=8192 query_cache_limit=1048576 query_cache_min_res_unit=4096 query_cache_size=0 query_cache_type=OFF query_cache_wlock_invalidate=OFF query_prealloc_size=8192 range_alloc_block_size=4096 range_optimizer_max_mem_size=8388608 read_buffer_size=262144 read_rnd_buffer_size=524288 session_track_gtids=OFF session_track_schema=ON session_track_state_change=OFF sha256_password_proxy_users=OFF show_compatibility_56=OFF show_old_temporals=OFF slave_net_timeout=120 slave_parallel_type=LOGICAL_CLOCK slave_parallel_workers=0 slave_rows_search_algorithms=TABLE_SCAN,INDEX_SCAN,HASH_SCAN slow_launch_time=2 slow_query_log=ON sort_buffer_size=868352 sql_auto_is_null=OFF sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION sql_safe_updates=OFF stored_program_cache=256 sync_binlog=1 table_definition_cache=8192 table_open_cache=8192 table_open_cache_instances=16 thread_cache_size=512 thread_handling=one-thread-per-connection thread_pool_oversubscribe=3 thread_pool_size=8 thread_stack=524288 time_zone=SYSTEM tmp_table_size=209715200 transaction_alloc_block_size=8192 transaction_prealloc_size=4096 tx_isolation=READ-COMMITTED updatable_views_with_limit=YES wait_timeout=3600
|
https://www.cnblogs.com/fuqian/p/16139165.html
https://blog.csdn.net/qq_29663071/article/details/80178160
这些字段在 MySQL 的 my.cnf 配置文件中用于定制数据库服务器的行为。我将详细解释其中的一些关键参数:
auto_increment_increment=1 和 auto_increment_offset=1: 这些设置影响 AUTO_INCREMENT 列的行为。auto_increment_increment 控制增量值,默认为1。auto_increment_offset 指定起始值,默认也为1。
automatic_sp_privileges=ON: 当设置为ON时,MySQL自动为存储程序(如存储过程和函数)授予权限。
avoid_temporal_upgrade=OFF: 控制MySQL在升级时是否自动升级时间类型的列。
back_log=3000: 定义在MySQL开始拒绝新的连接请求之前,可以挂起的连接请求数量。
binlog_cache_size=2097152: 设置二进制日志缓存的大小,影响事务的处理。
binlog_format=ROW: 设置二进制日志的格式,ROW表示记录每行的变化。
character_set_server=utf8 和 collation_server=utf8_general_ci: 这些参数设置服务器的默认字符集和校对规则。
connect_timeout=10: 设置客户端连接超时时间(秒)。
default_storage_engine=InnoDB: 设置默认的存储引擎。
innodb_buffer_pool_size=11811160064: InnoDB缓冲池的大小,对数据库的性能有重要影响。
max_connections=4500: 允许的最大连接数。
query_cache_size=0: 查询缓存的大小。0表示禁用查询缓存。
slow_query_log=ON: 慢查询日志的开关。当开启时,执行时间超过long_query_time秒的查询将被记录。
sql_mode: 设置SQL模式,控制MySQL的一些SQL语法和行为。
thread_cache_size=512: 线程缓存的大小,用于提高创建新线程的速度。
这只是配置文件中参数的一部分。每个参数都有其特定的作用,可以根据具体的需求和服务器环境进行调整以优化MySQL服务器的性能和行为。
20250320
ry 优化同步到readonly库的时间,调整的部分配置:
1 2 3 4 5 6 7 8
| # rongyi 20250320 innodb_buffer_pool_size = 3G #innodb_flush_log_at_trx_commit = 0 innodb_log_file_size = 1G #innodb_log_buffer_size = 64M #autocommit = 0 #foreign_key_checks = 0 #unique_checks = 0
|
什么意思?
https://stackoverflow.com/questions/59391611/how-to-improve-performance-of-mysql-dump-restore
20250407 改成4G试一下
1 2 3 4 5 6 7 8 9
| sudo bash
cd /etc/mysql/mysql.conf.d/
vim mysqld.cnf
systemctl restart mysql
|
这些是 MySQL 数据库的一些配置项,主要用于配置 InnoDB 存储引擎的行为。下面是每个配置项的解释:
innodb_buffer_pool_size = 3G: 这个参数设置 InnoDB 缓冲池的大小,缓冲池用于缓存表和索引的数据。将其设置为 3GB 意味着将分配 3GB 的内存来提高查询性能。
innodb_flush_log_at_trx_commit = 0: 这个参数控制日志刷写的频率。当设置为 0 时,InnoDB 会在每次事务提交时每秒写入日志,而不是立即将日志刷写到磁盘,从而提高性能,但在数据库崩溃的情况下可能会丢失最近的事务。
innodb_log_file_size = 1G: 这个参数设置 InnoDB 日志文件的大小为 1GB。日志文件用于记录数据库的所有更改,以便在崩溃后能够恢复数据。
innodb_log_buffer_size = 64M(被注释掉): 这个参数设置日志缓冲区的大小,缓冲区用于临时存储修改的日志记录。当事务提交时,这些记录会被写入日志文件。这里的设置可能是 64MB。
autocommit = 0(被注释掉): 这个参数决定是否自动提交事务。如果设置为 0,事务需要显式地提交,提供对事务处理的更好控制。
foreign_key_checks = 0(被注释掉): 这个参数控制外键检查。如果设置为 0,则在插入或更新数据时会禁用外键约束,有助于在某些情况下提高性能,尤其是在导入大数据量时。
unique_checks = 0(被注释掉): 这个参数控制唯一性检查。当设置为 0 时,数据库不会检查唯一性约束,可能会提高插入速度,但也会导致数据完整性问题。
总的来说,这些设置可以帮助优化 MySQL 数据库性能,但在更改这些参数时,要特别注意数据的完整性和崩溃恢复能力。
原文链接: https://dashen.tech/2020/01/05/MySQL配置文件my-cnf详解/
版权声明: 转载请注明出处.