Skip to content

Commit

Permalink
MDEV-27435: Support extra initialization file for mysql_install_db
Browse files Browse the repository at this point in the history
The mysql_install_db script is used to initialize the data directory.
However, if the user needs to apply some customized init commands (for
example to change user or password) they have to start the database
with `--skip-grant-tables` after the install script, and then restart
the database with normal mode.

To make it easier to include customization in the mysql_install_db
script, in this commit, a new parameter `extra-file` is added in
mysql_install_db script to support some extra customized init commands.

With this option we can support applying extra file containing sql for
mysql_install_db command line at runtime, which reduces the complexity
of customized initialization process.

This script is only used for install and is not included in the mtr
bootstrap file.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
  • Loading branch information
HugoWenTD authored and grooverdan committed Jan 7, 2022
1 parent 4f4d958 commit a81c75f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions man/mysql_install_db.1
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,21 @@ runs using your current login name and files and directories that it creates wil
.sp -1
.IP \(bu 2.3
.\}
.\" mysql_install_db: extra-file option
.\" extra-file option: mysql_install_db
\fB\-\-extra-file=\fR\fB\fIfile_path\fR\fR
.sp
Add user defined SQL file, to be executed following regular database initialization.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
.\" mysql_install_db: verbose option
.\" verbose option: mysql_install_db
\fB\-\-verbose\fR
Expand Down
18 changes: 18 additions & 0 deletions scripts/mysql_install_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cross_bootstrap=0
auth_root_authentication_method=socket
auth_root_socket_user=""
skip_test_db=0
extra_file=""

dirname0=`dirname $0 2>/dev/null`
dirname0=`dirname $dirname0 2>/dev/null`
Expand Down Expand Up @@ -95,6 +96,8 @@ Usage: $0 [OPTIONS]
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.
--extra-file=file Add user defined SQL file, to be executed following
regular database initialization.
All other options are passed to the mysqld program
Expand Down Expand Up @@ -178,6 +181,8 @@ parse_arguments()
--auth-root-socket-user=*)
auth_root_socket_user="$(parse_arg "$arg")" ;;
--skip-test-db) skip_test_db=1 ;;
--extra-file=*)
extra_file="$(parse_arg "$arg")" ;;

*)
if test -n "$pick_args"
Expand Down Expand Up @@ -399,6 +404,13 @@ do
fi
done

# Verify extra file exists if it's not null
if test ! -z "$extra_file" -a ! -f "$extra_file"
then
cannot_find_file "$extra_file"
exit 1
fi

if test ! -x "$mysqld"
then
cannot_find_file "$mysqld"
Expand Down Expand Up @@ -554,6 +566,12 @@ cat_sql()
then
cat "$mysql_test_db"
fi

# cat extra file if it's not null
if test ! -z "$extra_file"
then
cat "$extra_file"
fi
}

# Create the system and help tables by passing them to "mysqld --bootstrap"
Expand Down

0 comments on commit a81c75f

Please sign in to comment.