NYU Database Systems (Spring'2000)

Using MySQL

This page is meant to give a few tips on using MySQL at NYU. It is NOT a reference manual. For that, please visit the MySQL Site and the Documentation there.

You don't need to download MySQL; I've already set it up here. You can use it interactively or via a program.

Your Account and Database:

  1. I have already created an account and a database for you on the dbms. If your student id is xxxxx6789, then your user id on MySQL is "u6789", your password is "u6789123", and your database is "u6789db".
  2. You have permissions to create/query/update/drop tables in your own database.
  3. The first step you need to take it to log in to MySQL (as described in Interactive Usage) and change your password to something only you know. The command for that is:


Steps on Interactive Usage:

  1. Figure out your account/db details. Let's say your user id is u1234 and database is u1234db.
  2. The program to run is  "/home/poosala/public/sql/mysql  -h dept -u <userid> -p <database>"; so you will be typing /home/poosala/public/sql/mysql  -h dept -u u1234 -p u1234db
  3. This will ask you for password and log you into the database.
  4. Now you can type almost any SQL query, create tables, update them, etc.
  5. Type "show tables;" to see the list of tables in your database.
  6. For more information, go to the MySQL web site.
Steps on Usage from a C or C++ Program:

Calling MySQL from your Code:

Independent of C or C++, you will be making the similar calls to MySQL for querying and updating. For a detailed description of how to do this, you MUST refer to the documentation or the book on MySQL. (you don't really need to purchase this book for this project -- the test program and online docs should be enough).
I'm once again providing a small C++ (same goes for C) program that demonstrates the necessary calls - called test.cc.

Compilation:

This is for creating a binary from test.cc which includes both mysql and cgi functions in it. If your prorgram doesn't use cgi, then you don't need the cgi flags below. You don't need to copy the library and header files. Just use the flags I have used below.

C++:

g++ -L/home/poosala/public/sql -L/home/poosala/public/cgi -I/home/poosala/public/sql -I/home/poosala/public/cgi test.cc -o test -lmysqlclient -lnsl -lm -lsocket -lcgi++

C:
gcc -L/home/poosala/public/sql -L/home/poosala/public/cgi -I/home/poosala/public/sql -I/home/poosala/public/cgi test.cc -o test -lmysqlclient -lnsl -lm -lsocket -lcgi


Vishy Poosala, 2/21/2000

Back to Course Home Page