(1)进入数据库
C:\>mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.10a-nt
(2)创建数据库example
mysql> create database example;
Query OK, 1 row affected (0.03 sec)
mysql> use example;
Database changed
(3)创建表mytable
mysql> create table mytable(
-> name varchar(30),
-> phone varchar(10)
-> );
Query OK, 0 rows affected (0.05 sec)
(4)添加数据
mysql> insert into mytable values("homer simpson","555-1234");
Query OK, 1 row affected (0.02 sec)
mysql> insert into mytable values("bart simpson","555-4321");
Query OK, 1 row affected (0.00 sec)
mysql> insert into mytable values("lisa simpson","555-3214");
Query OK, 1 row affected (0.00 sec)
mysql> insert into mytable values("marge simpson","555-2314");
Query OK, 1 row affected (0.02 sec)
(5)查看数据表
mysql> select * from mytable;
+---------------+----------+
| name | phone |
+---------------+----------+
| homer simpson | 555-1234 |
| bart simpson | 555-4321 |
| lisa simpson | 555-3214 |
| marge simpson | 555-2314 |
+---------------+----------+
4 rows in set (0.00 sec)
此后创建了一个新用户叫:webuser,这个用户只能从localhost连接到数据库并可以连接到example数据库。下一步,我们必须指定webuser这个用户可以执行哪些操作:
mysql> grant select,insert,delete
-> on example.*
-> to webuser@localhost; //注意,要是添加密码的话用 -> identified by 密码;前面的不要用‘;’后面的用。
Query OK, 0 rows affected (0.06 sec)
此操作使webuser能够在每一个example数据库中的表执行select,insert和delete等查询操作。现在我们结束操作并退出mysql客户程序:
mysql> exit
Bye
C:\>
posted on 2005-04-29 23:05
dragon 阅读(429)
评论(3) 编辑 收藏 所属分类:
数据库知识