MySQL :: Unix@CMS :: University of Greenwich

advertisement
MySQL :: Unix@CMS :: University of Greenwich
MySQL
• Can I use MySQL?
• How and where can I connect to MySQL?
• Example MySQL command line session
• Is there a web interface for managing my MySQL database?
• How do I use mysqldump to backup my database?
Can I use MySQL?
All CMS students have access to their own MySQL database on the unix systems. This can have as many tables as
required and can be accessed via the command line, or from server side scripts written in PHP, Perl or Java.
NB: Your database is limited to a 30Mb quota − if you need increased space for project work then contact
UnixHelp@gre.ac.uk outlining your space requirements along with the name of your project supervisor.
Some essential facts:
Your database is hosted on the host studb.cms.gre.ac.uk
Your database is called mdb_USERID (replace USERID with your own userid; ie if your userid is wug01 then
your database is called mdb_wug01) Your userid to connect to the database is your normal unix userid
Your password to connect to the database is your original password as provided on your registration slip. (There is
currently no mechanism to change this. Even if you have changed your unix or windows password your MySQL
database password will not have changed.)
To access your database from the command line you should perform the following tasks.
1. login to student.cms.gre.ac.uk − Click Here for login instructions
2. mysql −h studb.cms.gre.ac.uk −u USERID −p mdb_USERID
Enter your password when prompted.
The latter command will connect you to your database once you enter your password in correctly.
E.g.
% mysql −h studb.cms.gre.ac.uk −u wug01 −p mdb_wug01
Once connected you may create and drop tables, insert, delete and select records.
For full details on what you should do, refer to the notes provided by your lecturer.
How and where can I connect to MySQL?
The security model deployed by the CMS Unix Team only allows certain pre−defined hosts to connect to the
MySQL server this excludes machines outside the CMS network.
You can connect to the MySQL server from the following hosts only.
student.cms.gre.ac.uk − The main student Unix server.
stuweb.cms.gre.ac.uk − The student Unix web server.
1
MySQL :: Unix@CMS :: University of Greenwich
cms−stu−iis.gre.ac.uk − The student windows web server.
Click Here for a PHP & MySQL Example
Click Here for a Perl & MySQL Example
Click Here for a Java & MySQL Example
Click Here for to find out how to use OpenOffice.org with MySQL
Example MySQL command line session
The following shows a full MySQL session from connection, viewing and manipulating the database to logging off
for the user wug01.
Text show in blue is just to illustrate the sequence of events. You wouldn't actually see this!
1. The user wug01 connects to her database (mdb_wug01) on the host studb.cms.gre.ac.uk
2. wug01 displays the tables available her database (none to start with)
3. creates a table called test, with one column of chars, called name.
4. Show the tables again.
5. insert the entry "foo" into the name column.
6. insert the entry "bar" into the name column.
7. select all the entry in the table test.
8. delete the table.
9. show available tables again.
10. Quit
wug01@bukowski:~% mysql −h studb.cms.gre.ac.uk −u wug01 −p mdb_wug01
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67 to server version: 3.23.53
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> show tables;
Empty set (0.00 sec)
mysql> create TABLE test (name CHAR(10));
Query OK, 0 rows affected (0.07 sec)
mysql> SHOW TABLES;
+−−−−−−−−−−−−−−−−−−−−−+
| Tables_in_mdb_wug01 |
+−−−−−−−−−−−−−−−−−−−−−+
| test
|
+−−−−−−−−−−−−−−−−−−−−−+
1 row in set (0.00 sec)
mysql> INSERT INTO test (name) VALUES ("foo");
Query OK, 1 row affected (0.04 sec)
mysql> INSERT INTO test (name) VALUES ("bar");
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM test;
+−−−−−−+
| name |
+−−−−−−+
| foo |
| bar |
2
MySQL :: Unix@CMS :: University of Greenwich
+−−−−−−+
2 rows in set (0.03 sec)
mysql> DROP TABLE test;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW TABLES;
Empty set (0.00 sec)
mysql> quit
Bye
Is there a web interface for managing my MySQL database?
Click here to access http://stumyadmin.cms.gre.ac.uk
How do I use mysqldump to backup my database?
Log into Unix and run mysqldump which is in the following format.
mysqldump −a −h [hostname] −p −u [userid] [database] > [output filename]
Example:
mysqldump −a −h studb −p −u wug01 mdb_wug01 > mdb_wug01.sql
3
Download