MySQL (发音为 \"My Ess Que Ell\")是 Tcx 公司(http://www.tcx.se)开发的一个多人使用、多执行绪的 SQL 资料库 Server。MySQL 主要的目标在快速、稳定和容易使用。
新增几笔资料,并查询看看:
mysql> insert into friends values(
-> "maa", "29016710", "46243046", "台北县新庄市"
-> );
Query OK, 1 row affected (0.00 sec)
mysql> insert into friends (name, icq, telphone, address ) Values (
-> "cxlin", "39425893", "7654321", "台北县"
-> );
Query OK, 1 row affected (0.01 sec)
mysql> select * from friends;
+-------+----------+----------+--------------+
| name | telphone | icq | address |
+-------+----------+----------+--------------+
| maa | 29016710 | 46243046 | 台北县新庄市 |
| cxlin | 7654321 | 39425893 | 台北县 |
+-------+----------+----------+--------------+
2 rows in set (0.00 sec)
第二个 insert 指令指定了资料栏位的插入顺序,用法较第一个为弹性,而第一个指令必须依资料表建立结构时的顺序插入资料。
更新、删除资料表记录:
mysql> update friends set address = "桃园县" where name = "cxlin";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from friends where name = "cxlin";
+-------+----------+----------+---------+
| name | telphone | icq | address |
+-------+----------+----------+---------+
| cxlin | 7654321 | 39425893 | 桃园县 |
+-------+----------+----------+---------+
1 row in set (0.00 sec)
mysql> delete from friends where name = "maa";
Query OK, 1 row affected (0.01 sec)
mysql> select * from friends;
+-------+----------+----------+---------+
| name | telphone | icq | address |
+-------+----------+----------+---------+
| cxlin | 7654321 | 39425893 | 桃园县 |
+-------+----------+----------+---------+
1 row in set (0.00 sec)
最後,建好资料库与资料表後,把 addbook 资料库中所有资料表的使用权限(select、insert、update、delete)授权给 maa@localhost(再次提醒,此处的 maa 为 MySQL 的使用者帐号,而非作业系统的 maa 帐号):
mysql> grant select, insert, update, delete
-> on addbook.*
-> to maa@localhost identified by '1234567';
Query OK, 0 rows affected (0.00 sec)
之後,可用 maa 的身份进入 MySQL 存取 addbook 资料库:
# /usr/local/mysql/bin/mysql -u maa -p addbook
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 211 to server version: 3.22.27
Type 'help' for help.
mysql> status
--------------
./mysql Ver 9.36 Distrib 3.22.27, for pc-linux-gnu (i686)
Connection id: 26
Current database: addbook
Current user: maa@localhost
Server version 3.22.27
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: