Skip to content

Commit 41658a0

Browse files
committed
Bug#18205019: RPM INSTALLATION GENERATES /USR/MY.CNF
A feature added to mysql_install_db in MySQL 5.6 was to generate my.cnf config file from template. The reason was a wish to set a specific value of sql_mode option for new installations. This is useful for many systems, however for some install methods and layouts this was not needed, and for some, even not wanted. Solution is add new option --keep-my-cnf to mysql_install_db. When used mysql_install_db will not generate my.cnf from template. Patch will also resolve issue mentioned in bug #68117 and #68318.
1 parent 1c1712e commit 41658a0

3 files changed

Lines changed: 50 additions & 225 deletions

File tree

Lines changed: 7 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,25 @@
11
diff --git a/scripts/mysql_install_db.pl.in b/scripts/mysql_install_db.pl.in
2-
index 440a977..7d068fc 100644
2+
index 1fa5164..4aa49ca 100644
33
--- a/scripts/mysql_install_db.pl.in
44
+++ b/scripts/mysql_install_db.pl.in
5-
@@ -75,6 +97,8 @@ Usage: $0 [OPTIONS]
6-
--help Display this help and exit.
7-
--ldata=path The path to the MySQL data directory. Same as --datadir.
8-
--no-defaults Don't read default options from any option file.
9-
+ --keep-my-cnf Don't try to create my.cnf based on template.
10-
+ Useful for systems with working, updated my.cnf.
11-
EOF1
12-
if ( $^O !~ m/^(MSWin32|cygwin)$/ ) {
13-
print <<EOF2;
14-
@@ -86,6 +110,7 @@ EOF2
5+
@@ -113,6 +113,7 @@ EOF2
156
print <<EOF3;
167
--rpm For internal use. This option is used by RPM files
178
during the MySQL installation process.
189
+ Implies --keep-my-cnf option.
1910
--skip-name-resolve Use IP addresses rather than hostnames when creating
2011
grant table entries. This option can be useful if
2112
your DNS does not work.
22-
@@ -149,6 +174,7 @@ sub parse_arguments
23-
24-
"skip-name-resolve",
25-
"verbose",
26-
+ "keep-my-cnf",
27-
"rpm",
28-
"help",
29-
"random-passwords",
30-
@@ -399,11 +431,16 @@ $basedir= "@prefix@" if ! $basedir; # Default
31-
# ----------------------------------------------------------------------
32-
33-
my $print_defaults;
34-
+my $keep_my_cnf = 0;
35-
36-
if ( $opt->{srcdir} and $opt->{basedir} )
13+
@@ -439,7 +440,7 @@ if ( $opt->{srcdir} and $opt->{basedir} )
3714
{
3815
error($opt,"Specify either --basedir or --srcdir, not both");
3916
}
17+
-if ( $opt->{'keep-my-cnf'} )
4018
+if ( $opt->{rpm} || $opt->{'keep-my-cnf'} )
41-
+{
42-
+ $keep_my_cnf = 1;
43-
+}
44-
if ( $opt->{srcdir} )
4519
{
46-
$opt->{builddir} = $opt->{srcdir} unless $opt->{builddir};
47-
@@ -425,7 +462,7 @@ my $config_file;
48-
my $copy_cfg_file;
49-
50-
# ----------------------------------------------------------------------
51-
-# This will be the default config file
52-
+# This will be the default config file (unless creation is unwanted)
53-
# ----------------------------------------------------------------------
54-
55-
my $cnfext = ( $^O =~ m/^(MSWin32|cygwin)$/ ) ? "ini" : "cnf";
56-
@@ -434,6 +471,11 @@ $config_file= "$basedir/my.$cnfext";
57-
58-
my $cfg_template= find_in_basedir($opt,"file","my-default.$cnfext",
59-
".", "share","share/mysql","support-files");
60-
+# Distros might move files
61-
+if ((! -r $cfg_template) && (-r "@pkgdatadir@/my-default.cnf")) {
62-
+ $cfg_template = "@pkgdatadir@/my-default.cnf";
63-
+}
64-
+
65-
-e $cfg_template or cannot_find_file("my-default.$cnfext");
66-
67-
$copy_cfg_file= $config_file;
68-
@@ -443,22 +485,21 @@ if (-e $copy_cfg_file)
69-
$copy_cfg_file =~ s/my.$cnfext/my-new.$cnfext/;
70-
# Too early to print warning here, the user may not notice
20+
$keep_my_cnf = 1;
7121
}
72-
-open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
73-
-if (open (CFG, "> $copy_cfg_file"))
74-
-{
75-
- while (<TEMPL>)
76-
- {
77-
- # Remove lines beginning with # *** which are template comments
78-
- print CFG $_ unless /^# \*\*\*/;
79-
+
80-
+if ( ! $keep_my_cnf ) {
81-
+ open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
82-
+ if (open (CFG, "> $copy_cfg_file")) {
83-
+ while (<TEMPL>) {
84-
+ # Remove lines beginning with # *** which are template comments
85-
+ print CFG $_ unless /^# \*\*\*/;
86-
+ }
87-
+ close CFG;
88-
+ } else {
89-
+ warning($opt,"Could not write to config file $copy_cfg_file: $!");
90-
+ $failed_write_cfg= 1;
91-
}
92-
- close CFG;
93-
+ close TEMPL;
94-
}
95-
-else
96-
-{
97-
- warning($opt,"Could not write to config file $copy_cfg_file: $!");
98-
- $failed_write_cfg= 1;
99-
-}
100-
-close TEMPL;
101-
102-
# ----------------------------------------------------------------------
103-
# Now we can get arguments from the groups [mysqld] and [mysql_install_db]
104-
@@ -621,7 +662,7 @@ if ( $opt->{'skip-name-resolve'} and $resolved and $resolved =~ /\s/ )
22+
@@ -664,7 +665,7 @@ if ( $opt->{'skip-name-resolve'} and $resolved and $resolved =~ /\s/ )
10523
}
10624

10725
# ----------------------------------------------------------------------
@@ -110,7 +28,7 @@ index 440a977..7d068fc 100644
11028
# ----------------------------------------------------------------------
11129

11230
# FIXME The shell variant uses "mkdir -p":
113-
@@ -654,7 +695,7 @@ if ($opt_user)
31+
@@ -697,7 +698,7 @@ if ($opt_user)
11432
}
11533
}
11634

@@ -119,18 +37,3 @@ index 440a977..7d068fc 100644
11937
{
12038
mkdir($dir, 0700) unless -d $dir;
12139
if ($opt_user and -w "/")
122-
@@ -848,7 +889,13 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
123-
"",
124-
"Support MySQL by buying support/licenses at http://shop.mysql.com");
125-
126-
- if ($copy_cfg_file eq $config_file and !$failed_write_cfg)
127-
+ if ($keep_my_cnf)
128-
+ {
129-
+ report($opt,
130-
+ "Note: new default config file not created.",
131-
+ "Please make sure your config file is current");
132-
+ }
133-
+ elsif ($copy_cfg_file eq $config_file and !$failed_write_cfg)
134-
{
135-
report($opt,
136-
"New default config file was created as $config_file and",
Lines changed: 7 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,25 @@
11
diff --git a/scripts/mysql_install_db.pl.in b/scripts/mysql_install_db.pl.in
2-
index 440a977..7d068fc 100644
2+
index 1fa5164..4aa49ca 100644
33
--- a/scripts/mysql_install_db.pl.in
44
+++ b/scripts/mysql_install_db.pl.in
5-
@@ -75,6 +97,8 @@ Usage: $0 [OPTIONS]
6-
--help Display this help and exit.
7-
--ldata=path The path to the MySQL data directory. Same as --datadir.
8-
--no-defaults Don't read default options from any option file.
9-
+ --keep-my-cnf Don't try to create my.cnf based on template.
10-
+ Useful for systems with working, updated my.cnf.
11-
EOF1
12-
if ( $^O !~ m/^(MSWin32|cygwin)$/ ) {
13-
print <<EOF2;
14-
@@ -86,6 +110,7 @@ EOF2
5+
@@ -113,6 +113,7 @@ EOF2
156
print <<EOF3;
167
--rpm For internal use. This option is used by RPM files
178
during the MySQL installation process.
189
+ Implies --keep-my-cnf option.
1910
--skip-name-resolve Use IP addresses rather than hostnames when creating
2011
grant table entries. This option can be useful if
2112
your DNS does not work.
22-
@@ -149,6 +174,7 @@ sub parse_arguments
23-
24-
"skip-name-resolve",
25-
"verbose",
26-
+ "keep-my-cnf",
27-
"rpm",
28-
"help",
29-
"random-passwords",
30-
@@ -399,11 +431,16 @@ $basedir= "@prefix@" if ! $basedir; # Default
31-
# ----------------------------------------------------------------------
32-
33-
my $print_defaults;
34-
+my $keep_my_cnf = 0;
35-
36-
if ( $opt->{srcdir} and $opt->{basedir} )
13+
@@ -439,7 +440,7 @@ if ( $opt->{srcdir} and $opt->{basedir} )
3714
{
3815
error($opt,"Specify either --basedir or --srcdir, not both");
3916
}
17+
-if ( $opt->{'keep-my-cnf'} )
4018
+if ( $opt->{rpm} || $opt->{'keep-my-cnf'} )
41-
+{
42-
+ $keep_my_cnf = 1;
43-
+}
44-
if ( $opt->{srcdir} )
4519
{
46-
$opt->{builddir} = $opt->{srcdir} unless $opt->{builddir};
47-
@@ -425,7 +462,7 @@ my $config_file;
48-
my $copy_cfg_file;
49-
50-
# ----------------------------------------------------------------------
51-
-# This will be the default config file
52-
+# This will be the default config file (unless creation is unwanted)
53-
# ----------------------------------------------------------------------
54-
55-
my $cnfext = ( $^O =~ m/^(MSWin32|cygwin)$/ ) ? "ini" : "cnf";
56-
@@ -434,6 +471,11 @@ $config_file= "$basedir/my.$cnfext";
57-
58-
my $cfg_template= find_in_basedir($opt,"file","my-default.$cnfext",
59-
".", "share","share/mysql","support-files");
60-
+# Distros might move files
61-
+if ((! -r $cfg_template) && (-r "@pkgdatadir@/my-default.cnf")) {
62-
+ $cfg_template = "@pkgdatadir@/my-default.cnf";
63-
+}
64-
+
65-
-e $cfg_template or cannot_find_file("my-default.$cnfext");
66-
67-
$copy_cfg_file= $config_file;
68-
@@ -443,22 +485,21 @@ if (-e $copy_cfg_file)
69-
$copy_cfg_file =~ s/my.$cnfext/my-new.$cnfext/;
70-
# Too early to print warning here, the user may not notice
20+
$keep_my_cnf = 1;
7121
}
72-
-open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
73-
-if (open (CFG, "> $copy_cfg_file"))
74-
-{
75-
- while (<TEMPL>)
76-
- {
77-
- # Remove lines beginning with # *** which are template comments
78-
- print CFG $_ unless /^# \*\*\*/;
79-
+
80-
+if ( ! $keep_my_cnf ) {
81-
+ open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
82-
+ if (open (CFG, "> $copy_cfg_file")) {
83-
+ while (<TEMPL>) {
84-
+ # Remove lines beginning with # *** which are template comments
85-
+ print CFG $_ unless /^# \*\*\*/;
86-
+ }
87-
+ close CFG;
88-
+ } else {
89-
+ warning($opt,"Could not write to config file $copy_cfg_file: $!");
90-
+ $failed_write_cfg= 1;
91-
}
92-
- close CFG;
93-
+ close TEMPL;
94-
}
95-
-else
96-
-{
97-
- warning($opt,"Could not write to config file $copy_cfg_file: $!");
98-
- $failed_write_cfg= 1;
99-
-}
100-
-close TEMPL;
101-
102-
# ----------------------------------------------------------------------
103-
# Now we can get arguments from the groups [mysqld] and [mysql_install_db]
104-
@@ -621,7 +662,7 @@ if ( $opt->{'skip-name-resolve'} and $resolved and $resolved =~ /\s/ )
22+
@@ -664,7 +665,7 @@ if ( $opt->{'skip-name-resolve'} and $resolved and $resolved =~ /\s/ )
10523
}
10624

10725
# ----------------------------------------------------------------------
@@ -110,7 +28,7 @@ index 440a977..7d068fc 100644
11028
# ----------------------------------------------------------------------
11129

11230
# FIXME The shell variant uses "mkdir -p":
113-
@@ -654,7 +695,7 @@ if ($opt_user)
31+
@@ -697,7 +698,7 @@ if ($opt_user)
11432
}
11533
}
11634

@@ -119,18 +37,3 @@ index 440a977..7d068fc 100644
11937
{
12038
mkdir($dir, 0700) unless -d $dir;
12139
if ($opt_user and -w "/")
122-
@@ -848,7 +889,13 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
123-
"",
124-
"Support MySQL by buying support/licenses at http://shop.mysql.com");
125-
126-
- if ($copy_cfg_file eq $config_file and !$failed_write_cfg)
127-
+ if ($keep_my_cnf)
128-
+ {
129-
+ report($opt,
130-
+ "Note: new default config file not created.",
131-
+ "Please make sure your config file is current");
132-
+ }
133-
+ elsif ($copy_cfg_file eq $config_file and !$failed_write_cfg)
134-
{
135-
report($opt,
136-
"New default config file was created as $config_file and",

scripts/mysql_install_db.pl.in

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22
# -*- cperl -*-
33
#
4-
# Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -99,6 +99,9 @@ Usage: $0 [OPTIONS]
9999
--help Display this help and exit.
100100
--ldata=path The path to the MySQL data directory. Same as --datadir.
101101
--no-defaults Don't read default options from any option file.
102+
--keep-my-cnf Don't try to create my.cnf based on template.
103+
Useful for systems with working, updated my.cnf.
104+
Deprecated, will be removed in future version.
102105
EOF1
103106
if ( $^O !~ m/^(MSWin32|cygwin)$/ ) {
104107
print <<EOF2;
@@ -173,6 +176,7 @@ sub parse_arguments
173176

174177
"skip-name-resolve",
175178
"verbose",
179+
"keep-my-cnf",
176180
"rpm",
177181
"help",
178182
"random-passwords",
@@ -429,11 +433,16 @@ $basedir= "@prefix@" if ! $basedir; # Default
429433
# ----------------------------------------------------------------------
430434

431435
my $print_defaults;
436+
my $keep_my_cnf = 0;
432437

433438
if ( $opt->{srcdir} and $opt->{basedir} )
434439
{
435440
error($opt,"Specify either --basedir or --srcdir, not both");
436441
}
442+
if ( $opt->{'keep-my-cnf'} )
443+
{
444+
$keep_my_cnf = 1;
445+
}
437446
if ( $opt->{srcdir} )
438447
{
439448
$opt->{builddir} = $opt->{srcdir} unless $opt->{builddir};
@@ -455,7 +464,7 @@ my $config_file;
455464
my $copy_cfg_file;
456465

457466
# ----------------------------------------------------------------------
458-
# This will be the default config file
467+
# This will be the default config file (unless creation is unwanted)
459468
# ----------------------------------------------------------------------
460469

461470
my $cnfext = ( $^O =~ m/^(MSWin32|cygwin)$/ ) ? "ini" : "cnf";
@@ -464,6 +473,11 @@ $config_file= "$basedir/my.$cnfext";
464473

465474
my $cfg_template= find_in_basedir($opt,"file","my-default.$cnfext",
466475
".", "share","share/mysql","support-files");
476+
# Distros might move files
477+
if ((! -r $cfg_template) && (-r "@pkgdatadir@/my-default.cnf")) {
478+
$cfg_template = "@pkgdatadir@/my-default.cnf";
479+
}
480+
467481
-e $cfg_template or cannot_find_file("my-default.$cnfext");
468482

469483
$copy_cfg_file= $config_file;
@@ -473,22 +487,21 @@ if (-e $copy_cfg_file)
473487
$copy_cfg_file =~ s/my.$cnfext/my-new.$cnfext/;
474488
# Too early to print warning here, the user may not notice
475489
}
476-
open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
477-
if (open (CFG, "> $copy_cfg_file"))
478-
{
479-
while (<TEMPL>)
480-
{
481-
# Remove lines beginning with # *** which are template comments
482-
print CFG $_ unless /^# \*\*\*/;
490+
491+
if ( ! $keep_my_cnf ) {
492+
open (TEMPL, $cfg_template) or error($opt, "Could not open config template $cfg_template");
493+
if (open (CFG, "> $copy_cfg_file")) {
494+
while (<TEMPL>) {
495+
# Remove lines beginning with # *** which are template comments
496+
print CFG $_ unless /^# \*\*\*/;
497+
}
498+
close CFG;
499+
} else {
500+
warning($opt,"Could not write to config file $copy_cfg_file: $!");
501+
$failed_write_cfg= 1;
483502
}
484-
close CFG;
485-
}
486-
else
487-
{
488-
warning($opt,"Could not write to config file $copy_cfg_file: $!");
489-
$failed_write_cfg= 1;
503+
close TEMPL;
490504
}
491-
close TEMPL;
492505

493506
# ----------------------------------------------------------------------
494507
# Now we can get arguments from the groups [mysqld] and [mysql_install_db]
@@ -878,7 +891,13 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") )
878891
"",
879892
"Support MySQL by buying support/licenses at http://shop.mysql.com");
880893

881-
if ($copy_cfg_file eq $config_file and !$failed_write_cfg)
894+
if ($keep_my_cnf)
895+
{
896+
report($opt,
897+
"Note: new default config file not created.",
898+
"Please make sure your config file is current");
899+
}
900+
elsif ($copy_cfg_file eq $config_file and !$failed_write_cfg)
882901
{
883902
report($opt,
884903
"New default config file was created as $config_file and",

0 commit comments

Comments
 (0)