A MySQL server has been created on the CS department computing system for use by COS425 students. The server is named studentdb. For each student in COS 425 a database has been created on the server; this database is named using the student's user name. For example, since my username in the CS department is aslp my database name is aslp and the username for the database is also aslp. The password for your database has been set to be the same as your username. (This should be changed right away as discussed below.) You can access studentdb only if logged onto a CS department computer. Each COS 425 student who did not already have a CS account has been given one for COS425 work. The login for the account is your Princeton user ID and the password has been set to your CIT password. You can access a CS machine by using a workstation in one of the public areas in the CS department or by ssh'ing to "portal.cs.princeton.edu".
Please note that your work on studentdb will NOT be backed-up; this database server is only for COS 425 exercises. You should periodically back up your own database by using the "mysqldump" command as described below.There are no logins on the machine studentdb; all access to studentdb is through client programs "mysql", "mysqldump", and "mysqladmin" run on one of the CS machines. The following instructions assume you are logged onto the CS machine named bolle and show the bolle prompt, but any machine in the department will work, as long as it has the mysql client (e.g. rayban).
bolle:$ mysqladmin -h studentdb -u [username] -p password [new password]
where: [username] is your user name, and
[new password] is your new password.
This will prompt you to enter your password which initially is
just your username.
Note: It's possible that your initial password is empty. In
this case, you just enter RETURN when you are asked for the
password.
bolle:$ mysql -h studentdb -u [username] -p [database name];
Enter password: [your password]
Recall that the database name is the same as your user name. After you enter your password at the prompt, you'll be in the mysql command-line utility.
create table professors(name char(40) not null, department char(3), primary key(name)); create table courses(cname char(40) not null, prof char(40), primary key(cname), foreign key prof_ref(prof) references professors(name)); show tables; describe courses; insert into professors values ('A', 'COS'); insert into professors values ('B', 'MAT'); insert into courses values ('C1', 'A'); insert into courses values ('C2', 'B'); insert into courses values ('C3', 'A');The following command will let mysql to execute all the commands in batch mode:
bolle:$ mysql -h studentdb -u [username] -p [database name] < batch-file
You may redirect the output of mysql to a file to save the result.
bolle:$ mysqldump -h studentdb -u [username] -p [database name] > [filename];
In this way you can back up your own database. We recommend you do this periodically. You can find more details in the MySQL Manual section on "mysqldump"
<? $machine = "studentdb.cs.princeton.edu"; $user = "<username>"; $passwd = "$lt;password>"; $db = "<dbname>"; $connect = mysql_connect($machine,$user,$passwd); if(!$connect) { echo "Error: couldn't connect to db!<BR>\n"; $error = mysql_error($connect); echo "<LI> $error\n"; exit; } mysql_select_db($db,$connect); \\ query code here... ?>
Reference: