Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobber205

macrumors 68020
Original poster
Nov 15, 2005
2,182
1
Oregon
Code:
alias mysql=//usr/local/mysql/bin/mysq
When I set that alias, it works only until I exit my current Terminal session.

Why is that?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
In your home folder (~), make a file named ".bash_profile" and put that line in it. It will then work every time you make a new terminal session.
 

mrichmon

macrumors 6502a
Jun 17, 2003
873
3
bobber205 said:
Code:
alias mysql=//usr/local/mysql/bin/mysq
When I set that alias, it works only until I exit my current Terminal session.

Why is that?

Another poster provided to solution. To your question "why is that?": by issuing the command alias mysql=/usr/local/mysql/bin/mysql you are setting the alias for the current shell. If you want to always have an alias available then you need to ensure that the alias is set automatically when an instance of the shell starts. If you create a .bash_profile file in your home directory then every shell command in that file will be executed automatically when a new shell starts. This means that all your aliases will be available.

By the way, it looks like you are trying to ensure that you can just type mysql to execute /usr/local/mysql/bin/mysql. The reason why you cannot just type mysql to run the command without the alias being set is that the /usr/local/mysql/bin directory is not in the list of paths that are searched to find commands to run. You can fix this by extending the path by using the following command in your .bash_profile file:

Code:
export PATH=${PATH}:/usr/local/mysql/bin

You can check the value of the PATH environment variable using the command set or using echo $PATH. You can add multiple new directories to your PATH variable by separating the paths using a ":" character.

The list of folders in the PATH variable are searched in the order that they are listed. You should only add new directories to the end of the PATH variable. Adding your own directories to the start of the PATH statement opens up a moderate security risk.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.