3

I'm having some issues with running mysql from terminal:

macmini:~ michael$ which mysql
/Applications/XAMPP/xamppfiles/bin/mysql
macmini:~ michael$ mysql
-bash: /usr/local/mysql/bin/mysql: No such file or directory

I had a previous installation at /usr/local/mysql/bin/mysql which no longer exists.

My path variable is as follows:

macmini:~ michael$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/Applications/XAMPP/xamppfiles/bin/:/usr/local/bin:/usr/X11/bin:/usr/local/MacGPG2/bin:/usr/texbin

Dropping to root seems to function correctly:

macmini:~ michael$ sudo bash
Password:
bash-3.2# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 66
Server version: 5.1.44 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

I seem to have found the issue - but I'm not sure how to change or remove this alias

macmini:~ michael$ type -a mysql
mysql is aliased to `/usr/local/mysql/bin/mysql'
mysql is /Applications/XAMPP/xamppfiles/bin/mysql
mysql is /Applications/XAMPP/xamppfiles/bin/mysql
5
  • there's no link, calling its full path works fine, the mysql from sudo bash is the one within XAMPP
    – Mikey
    Jun 25, 2012 at 13:33
  • 1
    Does which -a mysql still show the old executable?
    – slhck
    Jun 25, 2012 at 13:44
  • it displays these: /Applications/XAMPP/xamppfiles/bin/mysql,/Applications/XAMPP/xamppfiles/bin//mysql 2nd one looks fishy!
    – Mikey
    Jun 25, 2012 at 13:47
  • It does look weird indeed. There should be only one of these – although there's still no reference to your /usr/local/mysql remainders. Have you completely deleted that one? And, maybe logged out and back in?
    – slhck
    Jun 25, 2012 at 13:49
  • I've found the issue using type -a mysql - now I just need to work out how to remove this first entry!
    – Mikey
    Jun 25, 2012 at 14:45

2 Answers 2

3

Check ~/.bash_profile or ~/.profile for a command like this:

alias mysql='/usr/local/mysql/bin/mysql'

Remove it, then reload the shell.

3
  • I don't have a .bash_profile, all that's in my .profile is: export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
    – Mikey
    Jun 25, 2012 at 15:59
  • 2
    Per man bash there are only /etc/profile, ~/.bash_profile and ~/.profile which bash would read in your case. Are you sure you haven't sourced any other configuration files? If you haven't modified any of those files, then I have no idea where that alias is coming from. Have you reloaded your terminal in between? Does it work when you unalias mysql?
    – slhck
    Jun 25, 2012 at 16:44
  • 1
    Note that this won't last forever though — if that alias is created again, you'll have to unalias it every time. You can add the unalias to one of the shell's startup scripts, but that'll only cure the symptoms, not the cause. You could search all your files for alias to see where it's set though.
    – slhck
    Jun 25, 2012 at 16:55
0

Try hash mysql or hash -r to clear the command lookup structure:

hash [-lr] [-p filename] [-dt] [name]

For each name, the full file name of the command is determined by searching the directories in $PATH and remembered. If the -p option is supplied, no path search is performed, and filename is used as the full file name of the command. The -r option causes the shell to forget all remembered locations. The -d option causes the shell to forget the remembered location of each name. If the -t option is supplied, the full pathname to which each name corresponds is printed. If multiple name arguments are supplied with -t, the name is printed before the hashed full pathname. The -l option causes output to be displayed in a format that may be reused as input. If no arguments are given, or if only -l is supplied, information about remembered commands is printed. The return status is true unless a name is not found or an invalid option is supplied.

Note that you can use hash -t mysql to verify if the cached path lookup is indeed incorrect.

If hash -t shows that the correct path would be chosen and things still don't work, the next step is to check for aliases and functions. Test for an alias with:

alias mysql

This will either print -bash: alias: mysql: not found or show the alias definition. If there is a mysql alias defined, you'll have to grep for it in the ~/.bash*, ~/.profile and /etc/profile files.

Check for a bash function definition with:

shopt -s extdebug
typeset -fF mysql
shopt -u extdebug

This sets the extdebug shell option, then asks bash for the function mysql which, if it exists, will include where it is defined as mysql 42 /Users/foo/.bash_profile or similar (function name, line number, file).

If there is an alias or function, remove it from the file defining it and optionally remove it from the current shell with:

unalias mysql
unset -f mysql

unalias removes an alias definition, unset -f a function definition.

5
  • No luck :( macmini:~ michael$ hash mysql macmini:~ michael$ mysql -bash: /usr/local/mysql/bin/mysql: No such file or directory macmini:~ michael$ hash -r macmini:~ michael$ mysql -bash: /usr/local/mysql/bin/mysql: No such file or directory macmini:~ michael$ hash -t mysql -bash: hash: mysql: not found
    – Mikey
    Jun 25, 2012 at 13:34
  • And what if you set a full path with hash -p /Applications/XAMPP/xamppfiles/bin/mysql mysql? Jun 25, 2012 at 13:37
  • macmini:~ michael$ hash -t mysql /Applications/XAMPP/xamppfiles/bin/mysql it now displays, but running mysql results in the same error
    – Mikey
    Jun 25, 2012 at 13:39
  • Then this is not a bash or path error. Jun 25, 2012 at 13:40
  • what else could it be? running macmini:~ michael$ /Applications/XAMPP/xamppfiles/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. ... directly works fine
    – Mikey
    Jun 25, 2012 at 13:41

You must log in to answer this question.

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