Bug #20100 mysql_upgrade passes socket parameter to mysqlcheck etc. incorrectly
Submitted: 26 May 2006 21:59 Modified: 14 Nov 2006 3:47
Reporter: Anatoly Pidruchny (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.0.23-BK, 5.0.21 OS:Linux (Linux)
Assigned to: Bugs System CPU Architecture:Any

[26 May 2006 21:59] Anatoly Pidruchny
Description:
We use a non-default socket parameter for mysqld. This is a part of our my.cnf:

[mysqld]
datadir=/sm/mysql/data
socket=/sm/mysql/var/mysql.sock

[client]
socket=/sm/mysql/var/mysql.sock

When running mysql_upgrade, I got the error:

Got a failure from command:
cat /usr/local/mysql/share/mysql_fix_privilege_tables.sql | /usr/local/mysql/bin/mysql --no-defaults --force --user=root --host=localhost --database=mysql
Please check the above output and try again.

So, mysql_upgrade is running mysql with --no-defaults option. It means that the my.cnf file is not read by mysql. But mysql_upgrade does not pass the --socket=/sm/mysql/var/mysql.sock parameter to mysql in this case and as a result mysql fails.

Well, then I tried to run mysql_upgrade with --socket=/sm/mysql/var/mysql.sock option. I got the error:

Got a failure from command:
cat /usr/local/mysql/share/mysql_fix_privilege_tables.sql | /usr/local/mysql/bin/mysql --no-defaults --force --user=root --host=localhost --socket=\/sm\/mysql\/var\/mysql.sock --database=mysql
Please check the above output and try again.

Not much better. It tried to pass the socket parameter, but modified it putting backslashes before forward slashes for some reason and mysql failed again.

Finally I found a workaround. Running mysql_upgrade with --host=<ip address> parameter helped. mysql was able to connect to mysqld using TCP connection.

How to repeat:
Run mysqld with non-default socket file name and then try running mysql_upgrade.

Suggested fix:
I think two fixes are necessary in this case:
1. mysql_upgrade should pass the --sock parameter if [client] or [mysql_upgrade] section in my.cnf file has this option.
2. If --sock parameter is passed to the mysql_upgrade from the command line, then it should be passed to mysql correctly.
[27 May 2006 14:03] Valeriy Kravchuk
Thank you for a problem report. It looks similar to a known and verified bug #19452. Please, check.
[27 May 2006 23:03] Anatoly Pidruchny
Bug #19452 looks similar, but I think it is different. In fact, I can not reproduce the problem reported in bug #19452. My experience shows something different. What I see is that mysql_upgrade reads the [client] section, but putting host=host_name option in the [client] group does not cause the problem, reported in the bug #19452.

This bug #20100 is reported, because mysql_upgrade does not take into account the socket option (and possibly some other options) specified in the [client] group and passing --socket=<filename> from the command line also does not work correctly.
[31 May 2006 20:02] Richard McLane
I ran into this today as well.  It looks like the script is adding backslashes before the foward slashes to escape them out and then not parcing them correctly as escaped out foward slashes.  Here's what the socket option looks like when it fails:

--socket=\/var\/lib\/mysql\/main\/mysql.sock

I was able to get around it by running mysql_upgrade from the directory the socket was in and just passing it --socket=mysql.sock
[21 Jun 2006 7:36] Michal Marek
The problem is that the 'sed' call in parse_arguments() in
scripts/mysql_fix_privilege_tables.sh and scripts/mysql_upgrade.sh is
copy-pasted from mysqld_safe, but isn't needed acutally, because there is no
'eval' call in these scripts.

A plain 'args="$args $arg"' would work better.
[26 Jun 2006 13:28] Valeriy Kravchuk
Verified just as described:

openxs@suse:~/dbs/5.0> sh -x bin/mysql_upgrade --force --socket=/tmp/mysql5.sock
+ sh -x bin/mysql_upgrade --force --socket=/tmp/mysql5.sock
+ user=root
+ case "$1" in
+ find_my_print_defaults
+ test -x ./bin/my_print_defaults
+ print_defaults=./bin/my_print_defaults
+ args=
+ DATADIR=
+ bindir=
+ MY_BASEDIR_VERSION=
+ verbose=0
+ force=0
+ help_option=0
++ ./bin/my_print_defaults mysqld mysql_upgrade
+ parse_arguments
+ pick_args=
+ test '' = PICK-ARGS-FROM-ARGV
+ parse_arguments PICK-ARGS-FROM-ARGV --force --socket=/tmp/mysql5.sock
+ pick_args=
+ test PICK-ARGS-FROM-ARGV = PICK-ARGS-FROM-ARGV
+ pick_args=1
+ shift
+ for arg in '"$@"'
+ case "$arg" in
+ force=1
+ for arg in '"$@"'
+ case "$arg" in
+ test -n 1
++ echo --socket=/tmp/mysql5.sock
++ sed -e 's,\([^a-zA-Z0-9_.=-]\),\\\1,g'
+ args=' --socket=\/tmp\/mysql5.sock'
+ test 0 = 1
++ pwd
+ MY_PWD=/home/openxs/dbs/5.0
+ test -z ''
+ test -f ./share/mysql/english/errmsg.sys -a -x ./bin/mysqld
+ test -f ./share/mysql/english/errmsg.sys -a -x ./libexec/mysqld
+ MY_BASEDIR_VERSION=/home/openxs/dbs/5.0
+ bindir=/home/openxs/dbs/5.0/bin
+ test -z ''
+ test -d /home/openxs/dbs/5.0/data/mysql
+ test -d /home/openxs/dbs/5.0/var/mysql
+ DATADIR=/home/openxs/dbs/5.0/var
+ test '!' -x /home/openxs/dbs/5.0/bin/mysqlcheck
+ test '!' -f /home/openxs/dbs/5.0/var/mysql/user.frm
+ CHECK_FILE=/home/openxs/dbs/5.0/var/mysql_upgrade.info
+ test -f /home/openxs/dbs/5.0/var/mysql_upgrade.info -a 1 = 0
+ check_args='--check-upgrade --all-databases --auto-repair --user=root'
+ test 0 = 1
+ /home/openxs/dbs/5.0/bin/mysqlcheck --check-upgrade --all-databases --auto-rep
air --user=root '--socket=\/tmp\/mysql5.sock'
/home/openxs/dbs/5.0/bin/mysqlcheck: Got error: 2002: Can't connect to local MyS
QL server through socket '\/tmp\/mysql5.sock' (2) when trying to connect
+ '[' 2 = 0 ']'
+ /home/openxs/dbs/5.0/bin/mysql_fix_privilege_tables --silent --user=root '--so
cket=\/tmp\/mysql5.sock'
This script updates all the mysql privilege tables to be usable by
MySQL 4.0 and above.

This is needed if you want to use the new GRANT functions,
CREATE AGGREGATE FUNCTION, stored procedures, or
more secure passwords in 4.1

Got a failure from command:
cat /home/openxs/dbs/5.0/share/mysql/mysql_fix_privilege_tables.sql | /home/open
xs/dbs/5.0/bin/mysql --no-defaults --force --user=root --host=localhost --socket
=\/tmp\/mysql5.sock --database=mysql
Please check the above output and try again.

Running the script with the --verbose option may give you some information
of what went wrong.

If you get an 'Access denied' error, you should run this script again and
give the MySQL root user password as an argument with the --password= option
openxs@suse:~/dbs/5.0>

And yes, the fix suggested in the last comment works. Although, when executed from the command line:

openxs@suse:~/dbs/5.0> bin/mysql -uroot --socket=\/tmp\/mysql5.sock test
+ bin/mysql -uroot --socket=/tmp/mysql5.sock test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.23

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

mysql itself works with it from the command line. Because \ are pre-processed by shell...
[21 Oct 2006 2:38] Vladimir Shebordaev
The bug report describes faulty behavior of mysql_upgrade script which is know deprecated. 

As of 5.0.25 and above client/mysql_upgrade.c gets explicit communication parameters from the command line and just passes 'em to mysqlcheck as extra arguments if any. [client] configuration group is anyways read by mysql and mysqlcheck themselves. 

So, client/mysql_upgrade.c just needs to also pass communication parameters specified on the cmdline to mysql when it is about to fix privilege tables.
[21 Oct 2006 12:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14109

ChangeSet@1.2324, 2006-10-21 16:12:46+04:00, ted@ted.mysql.internal +1 -0
  BUG#20100 mysql_upgrade modified to accept all 
  the communication paramenters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[23 Oct 2006 3:49] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14126

ChangeSet@1.2324, 2006-10-23 07:47:54+04:00, ted@ted.mysql.internal +1 -0
  BUG#20100 mysql_upgrade modified to also accept all 
  the communication paramenters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[23 Oct 2006 4:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14127

ChangeSet@1.2324, 2006-10-23 08:13:50+04:00, ted@ted.mysql.internal +1 -0
  BUG#20100 mysql_upgrade modified to also accept all 
  the communication paramenters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[23 Oct 2006 6:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14147

ChangeSet@1.2324, 2006-10-23 09:43:59+04:00, ted@ted.mysql.internal +1 -0
  BUG#20100 mysql_upgrade modified to also accept all 
  the communication paramenters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[26 Oct 2006 12:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14427

ChangeSet@1.2339, 2006-10-26 16:30:16+04:00, ted@ted.mysql.internal +1 -0
  BUG#20100 fix: mysql_upgrade modified to also accept all 
  the communication paramenters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[7 Nov 2006 0:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14915

ChangeSet@1.2295, 2006-11-07 03:29:39+03:00, ted@ted.mysql.internal +1 -0
  BUG#20100 fix: mysql_upgrade modified to also accept all 
  the communication parameters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[7 Nov 2006 1:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14918

ChangeSet@1.2295, 2006-11-07 04:22:01+03:00, ted@ted.mysql.internal +1 -0
  BUG#20100 fix: mysql_upgrade modified to also accept all 
  the communication parameters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[7 Nov 2006 13:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14958

ChangeSet@1.2298, 2006-11-07 16:10:07+03:00, ted@ted.mysql.internal +1 -0
  BUG#20100 fix: mysql_upgrade modified to also accept all 
  the communication parameters from the cammand line
  and pass 'em correctly to both mysqlcheck and mysql
[8 Nov 2006 2:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/15003

ChangeSet@1.2298, 2006-11-08 05:45:50+03:00, ted@ted.mysql.internal +1 -0
  BUG#20100 fix: mysql_upgrade modified to also accept all 
  the communication parameters from the command line
  and pass 'em correctly to both mysqlcheck and mysql
[14 Nov 2006 3:47] Paul Dubois
Noted in 5.0.30 (not 5.0.29), 5.1.13 changelogs.

mysql_upgrade now passes all the parameters specified on the command
line to both mysqlcheck and mysql using the upgrade_defaults file.