安装MYSQL

1、在REDHAT版本的LINUX上安装MYSQL是一件非常容易的事情。先下载几个RPM文件,可以到http://www.tcx.se下载。
    MySQL-3.xx.xx-x.i386.rpm MySQL-devel-3.xx.xx-x.i386.rpm MySQL-client-3.xx.xx-x.i386.rpm

2、用命令"rpm -i"逐一安装。如:rpm -i MySQL-3.22.22-1.i386.rpm

3、建立数据库,如见一个名为"chat"的数据库用命令:mysqladmin create chat

4、设立用户。以root的身份用"mysql"进入查询状态。

mysql>
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into user (host,user,password) values('%','chat',password('password'));
Query OK, 1 row affected (0.00 sec)

mysql> insert into user (host,user,password) values('localhost','chat',password('password'));
Query OK, 1 row affected (0.00 sec)


这样就建立起一个用户名为"chat",密码为"password"的用户。

5、赋给用户"chat"访问chat数据库的权限。

mysql> insert into db (host,db,user,select_priv,insert_priv,update_priv, delete_priv,create_priv,drop_priv,Alter_priv) values('%','chat','chat','Y','Y','Y','Y','Y','Y','Y');
Query OK, 1 row affected (0.00 sec)

mysql> insert into db (host,db,user,select_priv,insert_priv,update_priv, delete_priv,create_priv,drop_priv,Alter_priv) values('localhost','chat','chat','Y','Y','Y','Y','Y','Y','Y');
Query OK, 1 row affected (0.00 sec)

mysql> \q
Bye
退出去。

mysqladmin reload 使生效。

6、以新创建的用户进入数据库的命令行查询:mysql -h 202.xxx.xxx.xxx -u chat -p 
或者:mysql -h localhost -u chat -p
建立表room,user,screenip

mysql> use chat
Database changed
mysql> create table room (port bigint NOT NULL,roomname varchar(40),pid varchar(6),num int,type char(1),host varchar(20));
Query OK, 0 rows affected (0.00 sec)

mysql> create table user (name varchar(21) NOT NULL,passwd varchar(11),lasttime bigint unsigned,exps bigint unsigned NOT NULL);
Query OK, 0 rows affected (0.00 sec)

mysql> create table screenip (ip varchar(15) NOT NULL,type char(1),no int);
Query OK, 0 rows affected (0.00 sec)
(注:如果要让字段大小写敏感,则将其设成'BINARY'类型的即可)
建立表room,user,screenip的索引

mysql> use chat
Database changed
mysql>alter table room add index (port), add primary key (port);
Query OK, 0 rows affected (0.00 sec)
mysql>alter table user add index (name), add primary key (name);
Query OK, 0 rows affected (0.00 sec)
mysql>alter table screenip add index (ip), add primary key (ip);
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye