next up previous contents index
Next: Perl DBI Up: MySQL Server Previous: Setting up mysqld   Contents   Index

Databases, tables, and tuples

Lets say that we want to create a database for Bob to use for his own stuff and give him rights to use this database. This is quite easy to do:

mysql> create database bob;
Query OK, 1 row affected (0.02 sec)

mysql> grant all on bob.* to bob@localhost;
Query OK, 0 rows affected (0.01 sec)

mysql> use bob
Database changes

That was easy. Let's create a table for Bob to use:

mysql> create table messages (
    -> number int(6),
    -> sender varchar(250),
    -> text varchar(250)
    -> );
Query OK, 0 rows affected (0.02 sec)

We can now look at the description of this table:

mysql> describe messages;
+--------+--------------+------+-----+---------+-------+
| Field  | Type         | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| number | int(6)       | YES  |     | NULL    |       |
| sender | varchar(250) | YES  |     | NULL    |       |
| text   | varchar(250) | YES  |     | NULL    |       |
+--------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

Okay, that looks good. Now to enter a tuple of data. (Tuples are often called records.)

mysql> INSERT INTO messages VALUES ('1', 'admin', 'Hello Bob, how are you?');
Query OK, 1 row affected (0.03 sec)

Now we can look at the table to see if the record is there:

mysql> select * from messages;
+--------+--------+-------------------------+
| number | sender | text                    |
+--------+--------+-------------------------+
|      1 | admin  | Hello Bob, how are you? |
+--------+--------+-------------------------+
1 row in set (0.00 sec)

It looks like the tuple is there.



Joseph Colton 2002-09-24