Skip to content

MDEV-28911: Add --init-command option to mariadb-{,admin,dump,binlog,check,import, show,slap,test}#4723

Open
HNOONa-0 wants to merge 1 commit intoMariaDB:mainfrom
HNOONa-0:MDEV-28911
Open

MDEV-28911: Add --init-command option to mariadb-{,admin,dump,binlog,check,import, show,slap,test}#4723
HNOONa-0 wants to merge 1 commit intoMariaDB:mainfrom
HNOONa-0:MDEV-28911

Conversation

@HNOONa-0
Copy link
Copy Markdown
Contributor

@HNOONa-0 HNOONa-0 commented Mar 2, 2026

  • The Jira issue number for this PR is: MDEV-28911

Description

A quick note on the implementation: I set it up so the command runs before mariadb-dump initializes its own default session settings. I originally thought it made more sense to put it after (so users could override the tool's internal defaults), but looking at the rest of the codebase, doing it before seems to be the established pattern. I decided to stick with the existing convention to keep things consistent. I also added a small MTR test file to verify the flag works as expected. Do you agree with this order of execution?

Right now, only the last init-command option will run. Is it desirable to allow users to specify multiple init commands?

Release Notes

Add --init-command option to mysqldump

How can this PR be tested?

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@grooverdan grooverdan added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 2, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

Please consider extending the MDEV text with a full functional description of the new option so it could be documented well.

Also, please make sure the text of your commit message complies with CODING_STANDARDS.md.

Some answers to your questions below.

Comment thread mysql-test/main/mysqldump-init-command.test Outdated
Comment thread client/mysqldump.cc Outdated
@HNOONa-0
Copy link
Copy Markdown
Contributor Author

HNOONa-0 commented Mar 7, 2026

failed tests work fine on my machine

Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for taking the extra effort to implement the common headers!

Stand by for the final review.

Comment thread client/mysqldump.cc Outdated
Comment thread include/common-cli-longopts.h
@HNOONa-0 HNOONa-0 force-pushed the MDEV-28911 branch 5 times, most recently from 3ac70a9 to 339a7fb Compare March 18, 2026 14:15
@HNOONa-0
Copy link
Copy Markdown
Contributor Author

HNOONa-0 commented Mar 18, 2026

Hello @gkodinov, I've implemented some of the modifications you suggested. For now, I've only applied them to a single client (mysql.cc) as a proof of concept. If you're happy with this selection of variables, I will apply them to other client files and maybe add a couple of tests too.

@gkodinov
Copy link
Copy Markdown
Member

gkodinov commented Apr 9, 2026

Hello @gkodinov, I've implemented some of the modifications you suggested. For now, I've only applied them to a single client (mysql.cc) as a proof of concept. If you're happy with this selection of variables, I will apply them to other client files and maybe add a couple of tests too.

It looks good.

@HNOONa-0 HNOONa-0 force-pushed the MDEV-28911 branch 2 times, most recently from 8a59c52 to 44c0456 Compare April 11, 2026 16:17
@grooverdan grooverdan changed the title MDEV-28911: Add --init-command option to mysqldump MDEV-28911: Add --init-command option to mariadb-{,admin,dump,binlog,check,import, show,slap,test} Apr 14, 2026
Copy link
Copy Markdown
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactorization. Where did the test case(s) that where previously there go? Can you include some form of --init-command in existing tests, e.g. mysql-test/main/mysqladmin.test and determine that this --init-command did have an affect (create new table?). Take note of the need for --replace-results as Windows executables have the .exe in the output.

Updating the man pages to include this option would be good too.

This sets up a good framework for readding bind address (#2750 - unfortunately reverted) as an option, for now or later.

Comment thread include/common-cli-vars.h Outdated
static char *opt_init_command = 0, *opt_client_plugin_dir = 0, *opt_default_auth = 0;

/* Options that are safe before any mysql_real_connect (including db=NULL). */
static inline void SET_COMMON_CLI_VARS_EXCEPT_INIT(MYSQL *mysql)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note even for a static inline we don't use upper case function names.

Comment thread include/common-cli-vars.h Outdated
*/

/* Connection options */
static uint opt_mysql_port = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static variables are 0 by default. And if there was a need, the style would be opt_mysql_port= 0

standard client options into a unified header. This ensures
consistent behavior for shared flags across all MariaDB clients.

The following changes were made:
- Added --init-command support to mysqldump.
- Refactored 10 client tools (mysql, mysqldump, etc.) to use
  common-cli-longopts.h for shared variable declarations.
- Removed redundant/duplicate option definitions to prevent
  future inconsistencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants