mysql startup shell problems -
since met many startup errors,i decide analyze mysql startup shell.while code fragment cannot understand clearly.
version:
mysql ver 14.14 distrib 5.5.43, osx10.8 (i386) using readline 5.1
368 # 369 # first, try find basedir , ledir (where mysqld is) 370 #
372 if echo '/usr/local/mysql/share' | grep '^/usr/local/mysql' > /dev/null 373 374 relpkgdata=echo '/usr/local/mysql/share' | sed -e 's,^/usr/local/mysql,,' -e 's,^/,,' -e 's,^,./,'
375 else 376 # pkgdatadir not relative prefix 377 relpkgdata='/usr/local/mysql/share' 378 fi
what's purpose of line 372? little weird
any appreciated.
at first glance, strange indeed... here's solution mystery.
372: if echo '/usr/local/mysql/share' | grep '^/usr/local/mysql' > /dev/null 373:
grep
returns true if matches , false if doesn't, testing whether string /usr/local/mysql/share
begins (^
) /usr/local/mysql
. output goes /dev/null
because don't need see it, want compare it.
"well," interject, "that's obvious enough. question why?" stick me.
if matches:
374: relpkgdata=echo '/usr/local/mysql/share' | sed -e 's,^/usr/local/mysql,,' -e 's,^/,,' -e 's,^,./,'
beginning /usr/local/mysql/share
, strip off beginning /usr/local/mysql
, strip off beginning /
prepend ./
.
so /usr/local/mysql/share
becomes ./share
.
otherwise, use string /usr/local/mysql/share
.
375: else 376: # pkgdatadir not relative prefix 377: relpkgdata='/usr/local/mysql/share'
"that's fine, too," hear say, "but why go through these gyrations (apparently) compare , massage 2 fixed literal strings?? know answer, what's tests , substitution?"
it's fair question.
my first suspicion there sort of magic bash hackery going on didn't recognize, no, code simple along lines.
my second suspicion, since notably absent mysql 5.0.96 (which not running keep on hand reference), abandoned attempt introduce new magical behavior mysqld_safe
never finished , replaced actual variables, testing , massaging of have made lot more sense doing same thing literal strings.
but, no. when tool have hammer, looks nail. is, example of doing simple... hard way. @ least that's looks me. there rational explanation. find answer, have source code (not binary) distribution.
mysql has lot of "hard-coded" defaults. turns out example of these.
in source file scripts/mysqld_safe.sh
, snippet above looks different:
if echo '@pkgdatadir@' | grep '^@prefix@' > /dev/null relpkgdata=`echo '@pkgdatadir@' | sed -e 's,^@prefix@,,' -e 's,^/,,' -e 's,^,./,'` else # pkgdatadir not relative prefix relpkgdata='@pkgdatadir@' fi
ah, source munging. pattern substitution.
when you're compiling mysql source, file scripts/makefile
contains instruction use sed
replace things @prefix@
, @pkgdatadir@
literal values. same thing, of course, happens when oracle or linux disto maintainers compile binary distribution source. these paths hard-coded many, many, many places in code, including script... resulting in otherwise incomprehensible comparison of 2 literal strings should have known answer to.
instead of testing @ build time, whether 1 path anchored substring of other, , "relpkgdata" value should expressed relative current directory , modifying script accordingly, logical test deferred until runtime, comparing 2 literals substituted in placeholders @ build time.
i've gone amount of detail, not because troubleshoot, because suspect won't. was, however, bizarre enough warrant further investigation.
if having difficulty getting mysql server running... well, shouldn't be, because it's well-established system , it should work. if /bin/sh
on system isn't symlink /bin/bash
, might want change mysqld_safe
's shebang line #!/bin/sh
#!/bin/bash
, beyond that, suspect sniffing down wrong rabbit hole looking @ mysqld_safe
bottom of issue. convoluted mysqld_safe
is, can't said isn't time-tested. say, "the problem somewhere else."
if may, i'll suggest familiarize of our other communities you're find answer need, particularly ask ubuntu, super user, server fault, , database administrators. familiarize each site's community, scope, , level of existing expertise each community expects on part of ask questions there, , search sites specific problem you're encountering. it's has seen , we've fixed on 1 of them, if not here on so.
Comments
Post a Comment