# Part 2.2Connecting to MySQL

The first thing that is needed with MySQL is to be able to access it.

## Connecting

Assuming that the database has been installed on the local machine, perhaps using MAMP, it can be accessed through the hostname localhost.

There are two ways of accessing this, assuming that MAMP is being used:

• Command line

## Connecting using the command line

Using the command line is recommended for power users but that does not mean it is not possible for anyone to learn this.

If the script, mysql, is found in the current directory or is linked to, then the command is as follows:

Command line
mysql --host=hostname -uusername -ppassword


However, if the mysql script is found in a different directory from the current one, it would simply be changed. Assuming that the mysql script is found in /Applications/MAMP/Library/bin/ then there are two options:

The first option involves changing directory to that location and then running mysql:

Command line
cd /Applications/MAMP/Library/bin/


The second is to run it with the directory in front:

Command line
/Applications/MAMP/Library/bin/mysql --host=hostname -uusername -ppassword


It is a good idea to create a script in a local directory to automatically connect to MySQL.