Skip to content

Commit c7358da

Browse files
committed
WL #6055 New default config file in MySQL 5.6
Bug #14725217 PLEASE ADD SQL_MODE=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES TO Bug #14729792 NO WARNING WHEN MY.CNF EXISTS IN /ETC/MYSQL Bug #14735440 WRONG WARNING MESSAGES SHOWN WHEN MYSQL_INSTALL_DB IS RUN Bug #14735448 NEW MY.CNF NOT CREATED WHEN --DEFAULTS-FILE IS USED WITH MYSQL_INSTALL_DB Extending mysql_install_db to install new default Handle cases where it exists already, or system file like /etc/my.cnf does
1 parent 2939c3f commit c7358da

3 files changed

Lines changed: 147 additions & 50 deletions

File tree

scripts/mysql_install_db.pl.in

Lines changed: 134 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
use Fcntl;
3838
use File::Basename;
39+
use File::Copy;
3940
use Getopt::Long;
4041
use Sys::Hostname;
4142
use Data::Dumper;
@@ -44,6 +45,7 @@ use strict;
4445
Getopt::Long::Configure("pass_through");
4546

4647
my @args; # Argument list filled in
48+
my $basedir;
4749

4850
##############################################################################
4951
#
@@ -165,20 +167,11 @@ sub parse_arguments
165167

166168
usage() if $opt->{help};
167169

168-
# To make these options acceptable for mysqld, we must prepend the name to the value -
169-
# but only if they are set, and have not been fixed already.
170-
if ( $opt->{'defaults-file'} && $opt->{'defaults-file'} !~ /^--/ )
170+
if ( $opt->{'no-defaults'} && ( $opt->{'defaults-extra-file'} ||
171+
$opt->{'defaults-file'} ) )
171172
{
172-
$opt->{'defaults-file'} = '--defaults-file=' . $opt->{'defaults-file'};
173-
}
174-
if ( $opt->{'defaults-extra-file'} && $opt->{'defaults-extra-file'} !~ /^--/ )
175-
{
176-
$opt->{'defaults-extra-file'} = '--defaults-extra-file=' . $opt->{'defaults-extra-file'};
177-
}
178-
# This option has no value, so we just have to spell it in full.
179-
if ( $opt->{'no-defaults'} && $opt->{'no-defaults'} !~ /^--/ )
180-
{
181-
$opt->{'no-defaults'} = '--no-defaults=';
173+
error($opt,
174+
"Cannot use both --no-defaults and --defaults-[extra-]file");
182175
}
183176

184177
@args = @ARGV if $pick_args;
@@ -206,7 +199,7 @@ sub find_in_basedir
206199
foreach my $part ( "$file","$file.exe","release/$file.exe",
207200
"debug/$file.exe","relwithdebinfo/$file.exe" )
208201
{
209-
my $path = "$opt->{basedir}/$dir/$part";
202+
my $path = "$basedir/$dir/$part";
210203
if ( -f $path )
211204
{
212205
return $mode eq "dir" ? dirname($path) : $path;
@@ -388,6 +381,17 @@ sub generate_random_password {
388381
my $opt = {};
389382
parse_arguments($opt, 'PICK-ARGS-FROM-ARGV', @ARGV);
390383

384+
# ----------------------------------------------------------------------
385+
# Actual basedir, not to be confused with --basedir option
386+
# ----------------------------------------------------------------------
387+
388+
if ( $opt->{srcdir} ) {
389+
$basedir= $opt->{builddir};
390+
} else {
391+
$basedir= $opt->{basedir};
392+
}
393+
$basedir= "@prefix@" if ! $basedir; # Default
394+
391395
# ----------------------------------------------------------------------
392396
# We can now find my_print_defaults. This script supports:
393397
#
@@ -408,25 +412,64 @@ if ( $opt->{srcdir} )
408412
$opt->{builddir} = $opt->{srcdir} unless $opt->{builddir};
409413
$print_defaults = "$opt->{builddir}/extra/my_print_defaults";
410414
}
411-
elsif ( $opt->{basedir} )
415+
else
412416
{
413417
$print_defaults = find_in_basedir($opt,"file","my_print_defaults","bin","extra");
414418
}
415-
else
419+
if ( ! $print_defaults )
416420
{
417421
$print_defaults='@bindir@/my_print_defaults';
418422
}
419423

420424
-x $print_defaults or -f "$print_defaults.exe"
421425
or cannot_find_file($print_defaults);
422426

427+
my $config_file;
428+
my $copy_cfg_file;
429+
430+
# ----------------------------------------------------------------------
431+
# This will be the default config file
432+
# ----------------------------------------------------------------------
433+
434+
$config_file= "$basedir/my.cnf";
435+
436+
my $cfg_template= find_in_basedir($opt,"file","my-default.cnf",
437+
"share","share/mysql","support-files");
438+
-e $cfg_template or cannot_find_file("my-default.cnf");
439+
440+
$copy_cfg_file= $config_file;
441+
if (-e $copy_cfg_file)
442+
{
443+
$copy_cfg_file =~ s/my.cnf/my-new.cnf/;
444+
# Too early to print warning here, the user may not notice
445+
}
446+
open (TEMPL, $cfg_template) or error("Could not open config template");
447+
open (CFG, "> $copy_cfg_file") or error("Could not open config file");
448+
while (<TEMPL>)
449+
{
450+
# Remove lines beginning with # *** which are template comments
451+
print CFG $_ unless /^# \*\*\*/;
452+
}
453+
close CFG;
454+
close TEMPL;
455+
423456
# ----------------------------------------------------------------------
424457
# Now we can get arguments from the groups [mysqld] and [mysql_install_db]
425458
# in the my.cfg file, then re-run to merge with command line arguments.
426459
# ----------------------------------------------------------------------
427460

461+
my $print_def_file;
462+
if ( $opt->{'defaults-file'} )
463+
{
464+
$print_def_file= $opt->{'defaults-file'};
465+
}
466+
else
467+
{
468+
$print_def_file= $config_file;
469+
}
470+
428471
my @default_options;
429-
my $cmd = quote_options($print_defaults,$opt->{'defaults-file'},
472+
my $cmd = quote_options($print_defaults,"--defaults-file=$print_def_file",
430473
"mysqld","mysql_install_db");
431474
open(PIPE, "$cmd |") or error($opt,"can't run $cmd: $!");
432475
while ( <PIPE> )
@@ -475,10 +518,9 @@ my ($bindir,$extra_bindir,$mysqld,$pkgdatadir,$mysqld_opt,$scriptdir);
475518

476519
if ( $opt->{srcdir} )
477520
{
478-
$opt->{basedir} = $opt->{builddir};
479-
$bindir = "$opt->{basedir}/client";
480-
$extra_bindir = "$opt->{basedir}/extra";
481-
$mysqld = "$opt->{basedir}/sql/mysqld";
521+
$bindir = "$basedir/client";
522+
$extra_bindir = "$basedir/extra";
523+
$mysqld = "$basedir/sql/mysqld";
482524
$mysqld_opt = "--language=$opt->{srcdir}/sql/share/english";
483525
$pkgdatadir = "$opt->{srcdir}/scripts";
484526
$scriptdir = "$opt->{srcdir}/scripts";
@@ -497,7 +539,6 @@ elsif ( $opt->{basedir} )
497539
}
498540
else
499541
{
500-
$opt->{basedir} = '@prefix@';
501542
$bindir = '@bindir@';
502543
$extra_bindir = $bindir;
503544
$mysqld = '@libexecdir@/mysqld';
@@ -604,12 +645,26 @@ push(@args, "--user=$opt->{user}") if $opt->{user};
604645

605646
# FIXME use --init-file instead of --bootstrap ?!
606647

648+
my $defaults_option = "";
649+
if ( $opt->{'no-defaults'} )
650+
{
651+
$defaults_option= "--no-defaults";
652+
}
653+
elsif ( $opt->{'defaults-file'} )
654+
{
655+
$defaults_option= "--defaults-file=$opt->{'defaults-file'}";
656+
}
657+
658+
my $defaults_extra= "--defaults-extra-file=$opt->{'defaults-extra-file'}"
659+
if $opt->{'defaults-extra-file'};
660+
607661
my $mysqld_bootstrap = $ENV{MYSQLD_BOOTSTRAP} || $mysqld;
608662
my $mysqld_install_cmd_line = quote_options($mysqld_bootstrap,
609-
$opt->{'defaults-file'},
663+
$defaults_option,
664+
$defaults_extra,
610665
$mysqld_opt,
611666
"--bootstrap",
612-
"--basedir=$opt->{basedir}",
667+
"--basedir=$basedir",
613668
"--datadir=$opt->{ldata}",
614669
"--log-warnings=0",
615670
"--loose-skip-ndbcluster",
@@ -660,8 +715,8 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
660715
{
661716
# using the implicit variable $_ !
662717
s/ABC123xyz/$escaped_password/e ; # Replace placeholder by random password
663-
print PIPE $_;
664-
}
718+
print PIPE $_;
719+
}
665720
close SQL3;
666721
tell_root_password();
667722
}
@@ -728,22 +783,22 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
728783
"",
729784
"See the manual for more instructions.");
730785
} else {
731-
report($opt,
732-
"PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !",
733-
"To do so, start the server, then issue the following commands:",
734-
"",
735-
" $bindir/mysqladmin -u root password 'new-password'",
736-
" $bindir/mysqladmin -u root -h $hostname password 'new-password'",
737-
"",
738-
"Alternatively you can run:",
739-
"",
740-
" $bindir/mysql_secure_installation",
741-
"",
742-
"which will also give you the option of removing the test",
743-
"databases and anonymous user created by default. This is",
744-
"strongly recommended for production servers.",
745-
"",
746-
"See the manual for more instructions.");
786+
report($opt,
787+
"PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !",
788+
"To do so, start the server, then issue the following commands:",
789+
"",
790+
" $bindir/mysqladmin -u root password 'new-password'",
791+
" $bindir/mysqladmin -u root -h $hostname password 'new-password'",
792+
"",
793+
"Alternatively you can run:",
794+
"",
795+
" $bindir/mysql_secure_installation",
796+
"",
797+
"which will also give you the option of removing the test",
798+
"databases and anonymous user created by default. This is",
799+
"strongly recommended for production servers.",
800+
"",
801+
"See the manual for more instructions.");
747802
}
748803

749804
if ( !$opt->{rpm} )
@@ -765,6 +820,28 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
765820
" http://www.mysql.com",
766821
"",
767822
"Support MySQL by buying support/licenses at http://shop.mysql.com");
823+
824+
if ($copy_cfg_file eq $config_file)
825+
{
826+
report($opt,
827+
"New default config file was created as $config_file and",
828+
"will be used by default by the server when you start it.",
829+
"You may edit this file to change server settings");
830+
}
831+
else
832+
{
833+
warning($opt,
834+
"Found existing config file $config_file on the system.",
835+
"Because this file might be in use, it was not replaced,",
836+
"but was used in bootstrap (unless you used --defaults-file)",
837+
"and when you later start the server.",
838+
"The new default config file was created as $copy_cfg_file,",
839+
"please compare it with your file and take the changes you need.");
840+
}
841+
foreach my $cfg ( "/etc/my.cnf", "/etc/mysql/my.cnf" )
842+
{
843+
check_sys_cfg_file ($opt, $cfg);
844+
}
768845
}
769846
exit 0
770847
}
@@ -801,6 +878,21 @@ else
801878
#
802879
##############################################################################
803880

881+
sub check_sys_cfg_file
882+
{
883+
my $opt= shift;
884+
my $fname= shift;
885+
886+
if ( -e $fname )
887+
{
888+
warning($opt,
889+
"Default config file $fname exists on the system",
890+
"This file will be read by default by the MySQL server",
891+
"If you do not want to use this, either remove it, or use the",
892+
"--defaults-file argument to mysqld_safe when starting the server");
893+
}
894+
}
895+
804896
sub report_verbose
805897
{
806898
my $opt = shift;

support-files/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
1616
IF(WIN32)
1717
SET(localstatedir "C:\\\\mysql\\\\data\\\\")
1818
SET(ini_file_extension "ini")
19+
SET(CNF_SOCKET_LINE "")
1920
ELSE()
2021
SET(localstatedir "${MYSQL_DATADIR}")
2122
SET(prefix "${CMAKE_INSTALL_PREFIX}")
@@ -30,6 +31,7 @@ ELSE()
3031
SET(MYSQLD_USER "mysql")
3132
SET(ini_file_extension "cnf")
3233
SET(HOSTNAME "hostname")
34+
SET(CNF_SOCKET_LINE "# socket = .....")
3335
ENDIF()
3436

3537
SET(dictionary "${CMAKE_INSTALL_PREFIX}/${INSTALL_SHAREDIR}/dictionary.txt" )
@@ -42,12 +44,11 @@ ELSE()
4244
SET(inst_location ${INSTALL_SUPPORTFILESDIR})
4345
ENDIF()
4446

45-
FOREACH(inifile my-huge my-innodb-heavy-4G my-large my-medium my-small)
46-
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${inifile}.cnf.sh
47-
${CMAKE_CURRENT_BINARY_DIR}/${inifile}.${ini_file_extension} @ONLY)
48-
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${inifile}.${ini_file_extension}
49-
DESTINATION ${inst_location} COMPONENT IniFiles)
50-
ENDFOREACH()
47+
SET(inifile my-default)
48+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${inifile}.cnf.sh
49+
${CMAKE_CURRENT_BINARY_DIR}/${inifile}.${ini_file_extension} @ONLY)
50+
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${inifile}.${ini_file_extension}
51+
DESTINATION ${inst_location} COMPONENT IniFiles)
5152

5253
IF(UNIX)
5354
SET(prefix ${CMAKE_INSTALL_PREFIX})

support-files/mysql.spec.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ echo "=====" >> $STATUS_HISTORY
988988
%doc %{src_dir}/Docs/ChangeLog
989989
%doc %{src_dir}/Docs/INFO_SRC*
990990
%doc release/Docs/INFO_BIN*
991-
%doc release/support-files/my-*.cnf
991+
%doc release/support-files/my-default.cnf
992992

993993
%doc %attr(644, root, root) %{_infodir}/mysql.info*
994994

@@ -1149,6 +1149,10 @@ echo "=====" >> $STATUS_HISTORY
11491149
# merging BK trees)
11501150
##############################################################################
11511151
%changelog
1152+
* Wed Oct 10 2012 Bjorn Munch <bjorn.munch@oracle.com>
1153+
1154+
- Replace old my-*.cnf config file examples with template my-default.cnf
1155+
11521156
* Fri Oct 05 2012 Joerg Bruehe <joerg.bruehe@oracle.com>
11531157

11541158
- Let the installation use the new option "--random-passwords" of "mysql_install_db".

0 commit comments

Comments
 (0)