Getting Started with MySQL

SQL is a programming language used to communicate with a relational database (think of a programmatic way to interact with data in a spreadsheet-like form). Multiple database packages use SQL and the most commonly used application in the open source community is MySQL. To install on Ubuntu:


sudo apt-get install mysql-server

As a part of the installation process you will be required to set the root password for MySQL. Then you can start it form the command line:


mysql -u root -p

To start MySQL from the command line one must specify the user (so far we only have root) and specify -p to prompt for the password:


ilya@lin1:~$ mysql -u root -p

From the MySQL prompt we can create a database and a new user and then grant access this user access to the newly created database.


mysql> create database test1;
mysql> create user 'user1'@'localhost' identified by 'password';
mysql> grant all on test1.* to 'user1';

To access the database as a newly created user we need to log out and log in:


mysql> mysql -u use1 -p

Now we can create a table in the database:


mysql> use test1;
mysql> mysql> CREATE TABLE example (
         id INT,
         data VARCHAR(100)
       );