2

MacOS here, although I'm 99% sure this is a Unix question.

I'm trying to see exactly where MySQL is installed. In a terminal I enter:

which mysql

And I get:

/usr/local/bin/mysql

So I see what's in that directory (ls -al /usr/local/bin/mysql) which gives me:

lrwxr-xr-x  1 myuser  admin  32 Mar 20  2017 /usr/local/bin/mysql -> ../Cellar/mysql/5.7.17/bin/mysql

Ok. Symbolic link. So I try to go to that symbolic link via ls -al ../Cellar/mysql/5.7.17/bin/mysql) and I get:

ls: ../Cellar/mysql/5.7.17/bin/mysql: No such file or directory

So where can I find ../Cellar/mysql/5.7.17/bin/mysql on my machine?

2
  • Could you check /usr/local/Cellar
    – unxnut
    Jan 12, 2018 at 20:26
  • or try readlink -f /usr/local/bin/mysql Jan 12, 2018 at 20:26

1 Answer 1

5

The link is relative to itself (not whatever the current working directory of your process is) so lop off the mysql and add the remainder

/usr/local/bin/../Cellar/mysql/5.7.17/bin/mysql

or in other words

/usr/local/Cellar/mysql/5.7.17/bin/mysql

there's a realpath(3) system call that may or may not be exposed by the shell or programming language in question for resolving such without the manual work. Portability suffers on these various shell commands:

$ cd /var/tmp
$ touch file
$ ln -s ../tmp/file ourlink
$ realpath ourlink                      # because I'm in mksh, YMMV
/private/var/tmp/file
$ readlink ourlink
../tmp/file
$ readlink -f ourlink
readlink: illegal option -- f
usage: readlink [-n] [file ...]
$ 

You could also install the GNU coreutils and use those if you want a consistent external command interface to realpath(3) (with even more complications if you want GNU readlink to be called readlink and appear in PATH before the vendor-provided one).

$ greadlink ourlink
../tmp/file
$ greadlink -f ourlink
/private/var/tmp/file
$ 
1
  • Ah, the .. was the giveaway! Jan 12, 2018 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .