MySQL in 5 minutes (Linux)

Want to learn SQL, but you don’t have time to study tons of books or browsing endlessly the Internet?
Then here we go with MySQL in 5 minutes crash course. After five minutes you’ll be able to create databases and tables, list and drop them. You’ll be able to fill and to query them. At the end of the course you’ll do a backup of your database, drop it, and restore it again. Of course most of the capabilities of MySQL won’t be mentioned, but If you find out, what you want to focus on, you can go deeper into details, e.g. at MySQL’s web-site. Check our their documentation there.
Let’s go, the clock’s ticking. (I assume you’re on Linux, I’m on Ubuntu 8.10 Intrepid Ibex)

MySQL in 5 minutes


  • Installing
    apt-get install mysql-server
  • Setting password for your database
    mysqladmin -u root password <my password here>
  • Time to log in:
    mysql -u root -p
  • Create a test database now:
    mysql>create database my_test_db;
  • Look at your mighty work:
    mysql>show databases;
  • Enter the context of your newly created db:
    mysql>use my_test_db;
  • Create a table in your newly created db:
    mysql>create table table1 ( name varchar(30), age int);
  • Look what you have done:
    mysql>show tables;
  • Look at the table stucture:
    mysql>describe table1;
  • Insert data into your table:
    mysql>insert into table1 ( name, age ) values ( "Andreas", 40 );
  • Look for all entries starting with an A and wonder:
    mysql>select * from table1 where name like "A%";
  • enter more data automatically. Download table1-inserts.txt:
    mysql my_test_db < table1-inserts.txt -u root -p 
  • Look for old farts (like me):
    mysql>select * from table1 where age between 30 and 40;
  • Calculate something:
    mysql>select ((22.1 * 12.9 ) / SQRT(2) ) -7;
  • Update/change content in a table:
    mysql>update table1 set age=35 where name = 'Hans';
  • You don't like Lisa anymore, remove her:
    mysql>delete from table1 where name="Lisa";