我电脑装上linux才一个月,特别是对rhel 4感觉很好,看过我贴的烂帖子的人,一定看得出是小菜鸟,看到网上很多姐妹对sql有兴趣(也可能是兄弟,但不是说菜鸟),反映不习惯,无从下手,看了半天书,感到很难。就装了个mysql学习一下。
我也没有专门研究过mysql,但由于以前在windows编程中常要用到sql数据库,会一些sql语法。才装上mysql,做了些摸索,行家莫笑。
1.打开mysql:
$mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 4.1.7
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
2.获取创建数据库及其表的权限:(这里练习,可以不用,后面用到)
mysql> grant all on samp_db.* to paul@localhost identified by "secret";
Query OK, 0 rows affected (0.10 sec)
3.创建samp_db(示例)数据库
mysql> create database samp_db;
Query OK, 1 row affected (0.06 sec)
4.使samp_db数据库成为当前数据库:
mysql> use samp_db;
Database changed
查看一下:
mysql> select database();
+------------+
| database() |
+------------+
| samp_db |
+------------+
1 row in set (0.00 sec)
5.在samp_db数据库中建立表:
mysql> create table test_tab (last_name varchar(15) not null, first_name varchar (15) not null, suffix varchar(5) null, city varchar(20) not null, state varchar( 2) not null, birth date not null, death date null );
Query OK, 0 rows affected (0.30 sec)
看看表的结构,是否符合要求:
mysql> describe test_tab;
+------------+-------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+------------+-------+
| last_name | varchar(15) | | | | |
| first_name | varchar(15) | | | | |
| suffix | varchar(5) | YES | | NULL | |
| city | varchar(20) | | | | |
| state | char(2) | | | | |
| birth | date | | | 0000-00-00 | |
| death | date | YES | | NULL | |
+------------+-------------+------+-----+------------+-------+
7 rows in set (0.06 sec)
看看数据库中有没有其它表:
mysql> show tables;
+-------------------+
| Tables_in_samp_db |
+-------------------+
| test_tab |
+-------------------+
1 row in set (0.00 sec)
再看看有哪些数据库;
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| samp_db |
| test |
+----------+
3 rows in set (0.00 sec)
6.试着在在表中加入一条记录:
mysql> insert into test_tab values('jinzhi','chen',null,'盐城yancheng','1','196 5.1.16',null); insert into test_tab values('jinzhi','chen',null,'盐城yancheng',
Query OK, 1 row affected (0.32 sec)
看看加入后是否符合要求:
mysql> select * from test_tab
-> ;
+-----------+------------+--------+--------------+-------+------------+-------+
| last_name | first_name | suffix | city | state | birth | death |
+-----------+------------+--------+--------------+-------+------------+-------+
| jinzhi | chen | NULL | 盐城yancheng | 1 | 1965-01-16 | NULL |
+-----------+------------+--------+--------------+-------+------------+-------+
1 row in set (0.06 sec)
mysql>
下面就看你的了:P
211.68.13.* 于 2006-07-14 23:24:03发表:
楼主能不能说一说怎么在红旗Linux上安装MySQL啊?谢了!
suo2800 于 2005-11-25 00:32:51发表:
好文,支持