MYSQL And TheCommand Line

A Few Simple Commands

Lately I have been trying to do more of my database work from the command line instead of using tools like phpmyadmin or MySQL Workbench. Although I mainly enjoy frontend development sometimes it is nice to think databases…

I decided to list out a few simple commands to help me commit them to memory and also help anyone else who may stumble accross this.

Open MySql in terminal - For Mac Using MAMP

/Applications/MAMP/Library/bin/mysql -uroot -p

This command will fire up the Mamp Mysql Command line socket your a mac. You might have to adjust the path if your system is setup differently.

Remeber to make sure Mysql is running on your version of Mamp before you do this.

List All Databases

show databases;

Will do just what it says and will show you a list of all the databases on your server.

Select A Database

use your_database_name_here;

Will select whatever database you specify.

View Tables

show tables;

Will show all the tables in your selected database.

View Database Structure

desc your_table_name_here;

This shows the tables structure along with primary keys etc.

Create Database

create database your_database_name_here;

Does just what it says :)

Import Sql file

source /Path/to/your-sql-file.sql;

Just set your path and filename and you are away.



Back to all posts