VMware下Linux源码安装设置MySQL服务

这里数据库的安装是LAMP的一部分

用到的mysql安装包

 mysql-standard-5.0.16-linux-i686.tar.gz

1、安装以及初始化的部分

[root@localhost ~]# cd /usr/local/

[root@localhost local]# tar zxvf mysql-standard-5.0.16-linux-i686.tar.gz

[root@localhost local]# cd mysql-standard-5.0.16-linux-i686
[root@localhost mysql-standard-5.0.16-linux-i686]# cat INSTALL-BINARY (查看套件安装的介绍,下边列出的是必要的部分)

     shell> groupadd mysql
     shell> useradd -g mysql mysql
     shell> cd /usr/local
     shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
     shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
     shell> cd mysql
     shell> scripts/mysql_install_db --user=mysql
     shell> chown -R root  .
     shell> chown -R mysql data
     shell> chgrp -R mysql .
     shell> bin/mysqld_safe --user=mysql &
[root@localhost local]# ln -s mysql-standard-5.0.16-linux-i686 mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# useradd -g mysql mysql

[root@localhost mysql]# scripts/mysql_install_db --user=mysql

[root@localhost mysql]# chown -R root .

[root@localhost mysql]# chown -R mysql data

[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# bin/mysqld_safe --user=mysql &(开启服务)

2、数据库操作的部分(包括添加、删除数据库、数据表,以及相关的数据操作)

[root@localhost ~]# cd /usr/local/mysql/bin/

[root@localhost bin]# ./mysql


mysql> show databases;

mysql> create database bbs;

mysql> use bbs;

mysql> create table list(

    -> id varchar(10) not null,

    -> name varchar(10) not null,

    -> password varchar(10) not null,

    -> numbers int default 0)

-> engine=MyISAM;

mysql> describe list;

+----------+-------------+------+-----+---------+-------+

| Field    | Type        | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| id       | varchar(10) | NO   |     |         |       |

| name     | varchar(10) | NO   |     |         |       |

| password | varchar(10) | NO   |     |         |       |

| numbers  | int(11)     | YES  |     | 0       |       |

+----------+-------------+------+-----+---------+-------+

4 rows in set (0.01 sec)

mysql> insert into list values ('001','sam','123456','20200');

Query OK, 1 row affected (0.00 sec)

 

mysql> insert into list values ('001','ken','123456','20300');

Query OK, 1 row affected (0.00 sec)

mysql> select * from list;

+-----+------+----------+---------+

| id  | name | password | numbers |

+-----+------+----------+---------+

| 001 | sam  | 123456   |   20200 |

| 001 | ken  | 123456   |   20300 |

+-----+------+----------+---------+

2 rows in set (0.00 sec)

mysql> update list set numbers='3000000'  where name='sam';

mysql> select * from list;

+-----+------+----------+---------+

| id  | name | password | numbers |

+-----+------+----------+---------+

| 001 | sam  | 123456   | 3000000 |

| 001 | ken  | 123456   |   20300 |

+-----+------+----------+---------+

2 rows in set (0.00 sec)

mysql> delete from list where name like 'ken';

mysql> delete from list;

mysql> drop database bbs;

mysql> quit


结束

上述数据库的操作是在无密码的状况下,这里可以采用下边的操作给它加上密码

[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqladmin -u root password '123456'
[root@localhost bin]# ./mysql -u root -p
Enter password:

相关推荐