How to access the mysql command line in Xampp from Mac OS X terminal

For the impatient:

How to setup the mysql command line after installing Xampp in Mac OS X:

Open your .profile file in Mac. This can be done by entering the terminal and typing:

open -t ~/.profile

Add the following line to your ./profile file. Replace the bolded part with the path where you installed Xampp, however by default this is the route and should work:


Open a new terminal window (Recommendation is to quit all terminal windows and then reopen) and type:


Thats it! Enjoy geeks!


For the people who have a little bit more time to learn what actually happened, here is the explanation.

When you install Xampp on Mac OS X it does come with mysql, however you may not access it from the command line by just typing the mysql command since the terminal does not know where to find the executable file.

In case you did not know, these type of knowledge of where to find files is given to the terminal through your profile file. In this file you will be able to export paths to your global $PATH variable that contains all the routes where your terminal will look into when receiving a command.

You may or may not have your profile file. It is tricky because if you are in Mac OS X Lion you will not see it. Hence, to find your profile file you will have to create it as I explained in a previous post.

The first instruction

open -t ~/.profile

Will either open or create your profile file. It will use the texteditor built in Mac which will be more confortable for this task than using vi or any other editor. If you have TextMate you may replace the open -t with mate command instead. The ~ will setup yourself in your home directory and the /.profile will give the route to the file which will be opened or created.

After this is done and with the command

export PATH=/opt/local/bin:/opt/local/sbin:/Applications/xampp/xamppfiles/bin:$PATH

you are exporting the path where Xampp keeps the command files, including those to run the mysql command line, into the $PATH variable. Therefore, when you type mysql in your terminal window, it will also search for this location for the command.

If you do not want to modify your $PATH variable, you would need to write all the full route plus the command in order to access the mysql command line. This means you would need to write…


…every single time that you want to run the mysql command line from the terminal.

After doing this steps it is recommended to close and restart the terminal. Sometimes the changes will not take effect and this will make you think that you did the process wrong. However, if you restart the terminal and type the mysql, you will be able to access the command line.


I hope this was useful.


Andrés Díaz

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>