ref – http://www.cyberciti.biz/faq/mysql-command-to-show-list-of-databases-on-server/
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/
Locate the DMG file compatible for your machine and download it
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.
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.
Go to your preferences, and you’ll see the SQL icon. Click on it and start the SQL server
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.
1 2 3 4 5 6 7 8 9 10 |
innochecksum mysql_config_editor mysqlcheck mysqlslap lz4_decompress mysql_embedded mysqld mysqltest_embedded my_print_defaults mysql_install_db mysqld-debug mysqlxtest myisam_ftdump mysql_plugin mysqld_multi perror myisamchk mysql_secure_installation mysqld_safe replace myisamlog mysql_ssl_rsa_setup mysqldump resolve_stack_dump myisampack mysql_tzinfo_to_sql mysqldumpslow resolveip mysql mysql_upgrade mysqlimport zlib_decompress mysql_client_test_embedded mysqladmin mysqlpump mysql_config mysqlbinlog mysqlshow |
/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
1 2 3 4 5 6 7 8 |
CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); |
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)