Instructions for tools to be used during the course

Last updated: November 13, 2005 11:22 PM


MySQL: Open source database system

Official Website
Download
Documentation (Suggest to go: Searchable Reference Manual, with user comments!)
Installation instructions (windows, linux, Mac OS X, NetWare)
Install using the source distribution
Post-installation Setup and Testing

How to use the utilies:
Read 4.7 MySQL Server-Side Scripts and Utilities & 4.8 MySQL Client-Side Scripts and Utilities

Newly Added: some tips of running MySQL server/client in user mode
Sample script for server, sample script for client. If you plan to run it on department machine, these scripts might be useful to give you an idea how to configure it. Just replace the directory with the one where you put MySQL package. And you also need to run scripts/mysql_install_db using similar arguments.

Quick Startup Solution:
( It is worth reading through the above instructions patiently if you want to know more about mysql)
shell> mysql; (Start it; if you run it the first time otherwise you need to use the command listed below)
mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password'); (set password for root which initially is empty!.)
(or shell> mysqladmin -u root -h localhost password 'new_password' )
mysql> FLUSH PRIVILEGES; (Save the change and make it work.)
(I found reading the user comment of Setting Up the Initial MySQL Privileges very helpful if you have problem on this step)
If you have problem, most of them are answered here: Problems and common errors

Common MySQL Commands:
\c to cancel a command
USE dbname to change to database
source scriptfile to run a script
\h to see the help


More readings may interest you:
Mysql-front: A SQLServer-like database management  front end.
Open Source Databases Comparison: MySQL, PostSQL and mSQL
Converters: From mysql's documentataion's Appendix B.2
Converter from MS-SQL to MySQL. By Michael Kofler. The mssql2mysql home page.
Perl program to convert Oracle databases to MySQL. Has same output format as mysqldump. By Johan Andersson.


kdb: Popular financial database handling time-ordered data at real-time speeds

To begin with, therefore, please download trial K from for a sun version and a pair of files for windows consisting of k.exe and k20.dll and a linux version . In both cases, you will also need db.kr .

More readings may interest you:
kdb & k:
kdb is a dababase written in k while k is a functional programming that looks terrible but is very useful
A Very Quick Look at Kdb from Dick Bowman
A Shallow Introduction to the K Programming Language by jjayson (nickname on the web)
How to call C from K
: Don Orth's description of how to call C from K. Prof. Shasha's introduction to k


Tuning Experiment (MySQL is suggested for Assignment 2 Question 9):

A step by step example to run some experiment on mysql:

0. Connect to mysql:

shell> mysql -h host -u user -p
Enter password: ********
Welcome to the MySQL monitor...
If your installed MySQL creates socket other than default, you can use
shell> mysql -S <sockfile> -h host -u user -p
Default sockfile on Linux/Unix is /tmp/mysql.sock.

1. Create a database databasename (you only need to do it once for one database)
mysql>CREATE DATABASE databasename;
(databasename is case-sensitive for unix environment)
mysql> show databases;
(You can use 'show databases;' to display what databases are in mysql)
mysql> USE databasename ;
(Select the databasename as the current database)
(Unzip the corresponding data files under the database's directory: by default at MYSQL_DIR/bin/mysql/databasename)
mysql> DROP DATABASE databasename ;
(Delete the databasename )

2.Create the table tablename:
mysql> source init.sql;
(Suppose the scripts(*.sql) files are under the client side's directory where you init the connect to mysql)
(The scripts for Oracle are most similar to mysql's, you can use them directly or by modifying a little)
(Try: change the tabs into spaces in init.sql if it reports syntax error)
or
mysql> CREATE TABLE tablename (fieldname1 integer, fieldname2 varchar(10));
mysql> DROP TABLE tablename;

3. Load the data from file into the table tablename:
mysql> source load.sql;

(If it does not work, rewrite the load.sql in the following syntax)
or
mysql>LOAD DATA INFILE "tablename_data.txt" INTO TABLE tablename fields terminated by '|';
(Note: you may need to remove the first line of each table which gives the description of the fields.)
mysql> select max(fieldname1) from tablename;
(Try a query to see whether data were loaded)

4. Create an index:
mysql> source index_add.sql;
or
mysql>CREATE INDEX index_name on table_name (field_name);

5. Drop an index:
mysql> source index_drop.sql;
or
mysql>DROP INDEX index_name on table_name;

6. Create a new user:
mysql> GRANT all on mydb.* to bob@localhost identified by 'alice';
(Create a user bob with password alice and allow it to do anything with the database named mydb)

7. Run the scripts:
mysql> source run.sql;
or
shell> mysql -u root -p databasename < run1.sql > run1.out

8. Exit mysql:
mysql> \q

9. Estimate script execution time:
shell> time mysql -u root -p databasename < run1.sql > run1.out

In mysql, if you type and execute the SQL command directly, the time cost will be shown at the end of the execution. However, if you source a script, no such information may not be provided. You need to use the utility, e.g. time in Linux/Unix as shown
above. To avoid any inaccuracy caused by typing password, you may create an user without password or use the account "test" set up by mysql automatically when it is installed. What you need to do is to grant user "test" the authority to change the database you created by the following command)
mysql> GRANT all on mydb.* to test@localhost


Performance Tracking Tools: Check your OS &DBMS's performance monitors

Tables generated by K

Testing samples for programming project