Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

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
  • phpMyAdmin

This article will show how both work.

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/
mysql --host=hostname -uusername -ppassword
		

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.

Connecting using phpMyAdmin

phpMyAdmin is one of the most popular ways of administering databases using a graphical interface.

With MAMP it can be used straight from the front page when the MAMP server is started or from the following URL: http://localhost:8888/MAMP/?page=phpmyadmin.

phpMyAdmin front page

The phpMyAdmin front page

Feedback 👍
Comments are sent via email to me.