Tag Archives: mysql

Mac: Install MySQL and use Terminal to use it

ref – http://www.cyberciti.biz/faq/mysql-command-to-show-list-of-databases-on-server/

Determine Kernal bit 32 or 64 for Mac


See whether you have the 32 or 64 bit processor

Go download the mysql dmg file from mysql’s developer page:

http://dev.mysql.com/downloads/mysql/

dmg_file_install

Locate the DMG file compatible for your machine and download it

mysql_mac

Let’s double click on the .dmg file, and double click the .pkg file to install it. Leave all the default options and continue through the installation wizard.

sql_installing

At a certain point, you’ll be given a default password. copy and paste it into a note editor because you’ll need it for the first log in, later in time.

Once you logged in the first time, you will be prompted to create a new password.

default_pwd

Go to your preferences, and you’ll see the SQL icon. Click on it and start the SQL server

preferences_mysql

start_mysql

Working with SQL in terminal

Open up the terminal.
Then go to the location:


cd /usr/local/mysql/bin

You’ll see all your mysql run commands in there.


/usr/local/mysql/bin/mysql -u root -p

enter your password

Showing all Database(s)

Let’s see all the databases in the SQL server.

mysql> show databases;

+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
+——————–+
4 rows in set (0.00 sec)

mysql>

Switch to Database

There are 4 databases so far. Let’s choose one and see what kind of tables are in there.

mysql> use mysql
Database changed
mysql> show tables;

Create a Database

But, we want to create our own custom database. Let’s do so.

mysql> CREATE DATABASE MyLocalDB;
Query OK, 1 row affected (0.03 sec)

Then create a table inside of our database

mysql> use MyLocalDB
Database changed

mysql> CREATE TABLE Persons
-> (
-> PersonID int,
-> LastName varchar(255),
-> FirstName varchar(255),
-> Address varchar(255),
-> City varchar(255)
-> );
Query OK, 0 rows affected (0.35 sec)

Insert a row into your table

mysql> insert into Persons (PersonID, LastName, FirstName, Address, City) values (‘123’, ‘Saor’, ‘Rick’, ‘132 Nowhere street’, ‘Liberty Hall’);
Query OK, 1 row affected (0.07 sec)