[MDEV-14580] mysql_install_db "Could not find ./bin/my_print_defaults" Created: 2017-12-05  Updated: 2019-01-21  Resolved: 2019-01-21

Status: Closed
Project: MariaDB Server
Component/s: Scripts & Clients
Affects Version/s: 10.3.3
Fix Version/s: 10.1.38, 5.5.63, 10.0.38, 10.2.22, 10.3.13

Type: Bug Priority: Critical
Reporter: Daniel Black Assignee: Sergei Golubchik
Resolution: Fixed Votes: 1
Labels: contribution, foundation

Issue Links:
Duplicate
duplicates MDEV-14617 mysql_install: if no basedir set, use... Closed
Sprint: 10.1.32

 Description   

a default compiled mariadb (CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql) installed, with make install.

path set:

$ export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts
 
$ mysql_install_db --defaults-file=~/my.cnf --datadir=~/data2
 
FATAL ERROR: Could not find ./bin/my_print_defaults

A work around is to include `--basedir=/usr/local/mysql` in the mysql_install_db options however this should be default on an install.

Recently changed in all versions (though problem probably existed before hand).
https://github.com/MariaDB/server/commit/52516706c86f9f66c76836eabde7e2477694bac3



 Comments   
Comment by Sergei Golubchik [ 2018-04-04 ]

I think it could've been fixed simpler, by not resetting $basedir:

diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh
--- a/scripts/mysql_install_db.sh
+++ b/scripts/mysql_install_db.sh
@@ -251,8 +251,11 @@ then
     cannot_find_file my_print_defaults $basedir/bin $basedir/extra
     exit 1
   fi
-else
+elif test -x "@bindir@/my_print_defaults"
   print_defaults="@bindir@/my_print_defaults"
+else
+then
+  basedir="@CMAKE_INSTALL_PREFIX@"
+  print_defaults="@CMAKE_INSTALL_PREFIX@/@bindir@/my_print_defaults"
 fi
 
 if test ! -x "$print_defaults"

But should it default to /usr/loca//mysql? tarball is supposed to be fully relocatable, it can be unpacked anywhere. I don't know if it's safe to assume that it'll be unpacked into /usr/local/mysql.

Comment by Daniel Black [ 2018-04-04 ]

How about something like the following so we fall back to path if not found. At least the user can fix that without editing the instlaled file.

diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh
index 5afeb6a6f47..eff435962d3 100644
--- a/scripts/mysql_install_db.sh
+++ b/scripts/mysql_install_db.sh
@@ -285,14 +285,16 @@ then
     cannot_find_file my_print_defaults $basedir/bin $basedir/extra
     exit 1
   fi
-else
+elif test -x "@bindir@/my_print_defaults"
+then
   print_defaults="@bindir@/my_print_defaults"
-fi
-
-if test ! -x "$print_defaults"
+elif test -x "@CMAKE_INSTALL_PREFIX@/@bindir@/my_print_defaults"
 then
-  cannot_find_file "$print_defaults"
-  exit 1
+  basedir="@CMAKE_INSTALL_PREFIX@"
+  print_defaults="@CMAKE_INSTALL_PREFIX@/@bindir@/my_print_defaults"
+else
+# let the path find it
+  print_defaults="my_print_defaults"
 fi
 
 # Now we can get arguments from the groups [mysqld] and [mysql_install_db]

Comment by Sergei Golubchik [ 2018-04-11 ]

My point is, if there's one mariadb tarball installed in /usr/local, and another one in, say, ~/mariadb-test or, for example, /usr/local/mariadb-10.3, then a user would rather prefer an error if --basedir is not specified, rarher then picking up incorrect mariadb installation automatically. After all, mysql_install_db is run only once.

On the other hand, using the dirname $0 as a hint to guess the correct path seems pretty safe. Just need to be portable enough.

Comment by Rasmus Johansson (Inactive) [ 2019-01-03 ]

danblack There were some comments from Serg. Is there something that you could change accordingly in the patch?

Comment by Daniel Black [ 2019-01-12 ]

Updated PR created based purely on dirname. I haven't found any suggestion is anything other than posix.

Related, fixes user problem, https://github.com/MariaDB/server/pull/760#issuecomment-452903667, and hopefully eliminates the need for https://git.alpinelinux.org/aports/tree/main/mariadb/fix-mysql-install-db-path.patch in alpine.

Generated at Thu Feb 08 08:14:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.