Tuesday 7 February 2017

MySQL on Ubuntu

1) To check your hostname run:
       hostname
       hostname -f

2)Update your system:
        sudo apt-get update
        sudo apt-get upgrade

3)Install MySQL
        sudo apt-get install mysql-server

      Enter password

4) MySQL Server
       sudo mysql_secure_installation

5)Root Login
       mysql -u root -p

6)Create a New MySQL User and Database
   
    create database testdb;
    create user 'testuser'@'localhost' identified by 'password';
    grant all on testdb.* to 'testuser';
   
      You can shorten this process by creating the user while assigning database permissions:

     create database testdb;
     grant all on testdb.* to 'testuser' identified by 'password';


7)Exit MySQL.
    exit


Create a Sample Table

   a) Log back in as testuser
        mysql -u testuser -p

   b)Create a sample table called customers. This creates a table with  a customer ID field of the type INT for integer (auto-incremented for new records, used as the primary key), as well as two fields for storing the customer’s name.

create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);

c)Then exit MySQL.
     exit