MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerStorageMySQL

Function registerStorageMySQL

src/Storages/StorageMySQL.cpp:397–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395
396void registerStorageMySQL(StorageFactory & factory);
397void registerStorageMySQL(StorageFactory & factory)
398{
399 factory.registerStorage("MySQL", [](const StorageFactory::Arguments & args)
400 {
401 MySQLSettings mysql_settings; /// TODO: move some arguments from the arguments to the SETTINGS.
402 auto configuration = StorageMySQL::getConfiguration(args.engine_args, args.getLocalContext(), mysql_settings, &args.table_id);
403
404 if (args.storage_def->settings)
405 mysql_settings.loadFromQuery(*args.storage_def);
406
407 if (!mysql_settings[MySQLSetting::connection_pool_size])
408 throw Exception(ErrorCodes::BAD_ARGUMENTS, "connection_pool_size cannot be zero.");
409
410 mysqlxx::PoolWithFailover pool = createMySQLPoolWithFailover(configuration, mysql_settings);
411
412 return std::make_shared<StorageMySQL>(
413 args.table_id,
414 std::move(pool),
415 configuration.database,
416 configuration.table,
417 configuration.replace_query,
418 configuration.on_duplicate_clause,
419 args.columns,
420 args.constraints,
421 args.comment,
422 args.getContext(),
423 mysql_settings);
424 },
425 {
426 .supports_settings = true,
427 .supports_schema_inference = true,
428 .source_access_type = AccessTypeObjects::Source::MYSQL,
429 .has_builtin_setting_fn = MySQLSettings::hasBuiltin,
430 },
431 Documentation{
432 .description = R"DOCS_MD(
433The MySQL engine allows you to perform `SELECT` and `INSERT` queries on data that is stored on a remote MySQL server.
434
435## Creating a table {#creating-a-table}
436
437```sql
438CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
439(
440 name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1],
441 name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2],
442 ...
443) ENGINE = MySQL({host:port, database, table, user, password[, replace_query, on_duplicate_clause] | named_collection[, option=value [,..]]})
444SETTINGS
445 [ connection_pool_size=16, ]
446 [ connection_max_tries=3, ]
447 [ connection_wait_timeout=5, ]
448 [ connection_auto_close=true, ]
449 [ connect_timeout=10, ]
450 [ read_write_timeout=300, ]
451 [ enable_compression=false ]
452;
453```
454

Callers 1

registerStoragesFunction · 0.85

Calls 6

registerStorageMethod · 0.80
getLocalContextMethod · 0.80
ExceptionClass · 0.50
loadFromQueryMethod · 0.45
getContextMethod · 0.45

Tested by

no test coverage detected