Saturday, January 4, 2014

Installing MySQL on Ubuntu


  1. Update the OS
    1. sudo apt-get update
  2. Install MySQL
    1. sudo apt-get install mysql-server (You will be prompted for root password. Dont forget the password)
  3. It is not advisable to open mysql connections to outside of localhost. However if you must, then
    1. sudo vi /etc/mysql/my.cnf
    2. Comment out the line "bind-address 127.0.0.1"
  4. After install, create a non-root user ID
    1. mysql -u root -h 127.0.0.1 -p (when prompted enter the root password)
    2. create user 'userid'@'localhost' identified by 'passwd'
    3. grant all privileges on *.* to 'userid'@'%' identified by 'passwd' with grant option;
    4. flush privileges;
    5. quit
  5. Restart MySQL
    1. sudo /etc/init.d/mysql restart
  6. Create tables, Insert data, Select data
    1. mysql -u <userid> -h <host name> -p
    2. create database <db name>;
    3. use <db name>;
    4. create table test1 (fname varchar(20));
    5. insert into test1 values('John');
    6. select * from test1;
  7. Install a SQL GUI client (Toad or RapidSQL or SequelPro(for mac), etc)
  8. For bulk import of a CSV file (reference)
    1. mysqlimport  --ignore-lines=1 --fields-terminated-by=, --columns='ID,Name,Phone,Address' --local -u root -p Database /path/to/csvfile/TableName.csv 
  9. Happy SQLing!

No comments:

Post a Comment