Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
    
there's no link, calling its full path works fine, the mysql from sudo bash is the one within XAMPP –  Mikey Jun 25 '12 at 13:33
1  
Does which -a mysql still show the old executable? –  slhck Jun 25 '12 at 13:44
    
it displays these: /Applications/XAMPP/xamppfiles/bin/mysql,/Applications/XAMPP/xamppfiles/bin//‌​mysql 2nd one looks fishy! –  Mikey Jun 25 '12 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 '12 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 '12 at 14:45
add comment

2 Answers 2

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

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

Remove it, then reload the shell.

share|improve this answer
    
I don't have a .bash_profile, all that's in my .profile is: export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH –  Mikey Jun 25 '12 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 '12 at 16:44
    
unalias mysql did the trick :D thanks –  Mikey Jun 25 '12 at 16:46
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 '12 at 16:55
add comment

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.

share|improve this answer
    
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 '12 at 13:34
    
And what if you set a full path with hash -p /Applications/XAMPP/xamppfiles/bin/mysql mysql? –  Martijn Pieters Jun 25 '12 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 '12 at 13:39
    
Then this is not a bash or path error. –  Martijn Pieters Jun 25 '12 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 '12 at 13:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.