3. 创建第2个数据库

源码安装最大的优点就是灵活(缺点当然也很明显:复杂),不过能够创建一个数据库出来,再创建第二个自然也不在话下,事实上创建第2个数据库与第1个从步骤上看,基本也没什么区别,只要注意修改相关路径,和mysql运行的端口号即可。

创建目录并修改权限:

    [root@mysqldb2 mysql]# mkdir /data/mysqldata/3307

    [root@mysqldb2 mysql]# cd /data/mysqldata/3307/

    [root@mysqldb2 3307]# mkdir data binlog tmp innodb_ts innodb_log

    [root@mysqldb2 3307]# cd /data/mysqldata

    [root@mysqldb2 mysqldata]# chown mysql:mysql 3307 -R

复制初始化参数文件:

    [root@mysqldb2 3307]# cp ../3306/my.cnf ./

修改初始化参数值,主要为路径和端口:

    [root@mysqldb2 3307]# vi my.cnf 

命令符下输入:

     s/3306/3307/g

替换文件中所有3306为3307

编辑server-id的值,指定一个与3306数据库不同的值,比如说303307:

    server-id = 303307

创建数据库:

    [root@mysqldb2 3307]# mysql_install_db --user=mysql --datadir=/data/mysqldata/3307/data

    Installing MySQL system tables...

    OK

    Filling help tables...

    OK

    ..........

    ..........

启动数据库:

    [root@mysqldb2 3307]# mysqld_safe --defaults-file=/data/mysqldata/3307/my.cnf &

设置超级用户密码:

    [root@mysqldb2 3307]# mysqladmin -uroot password ¨verysafe¨ -S /data/mysqldata/3307/mysql.sock 

随后,就可以通过mysql登录了:

    [root@mysqldb2 3307]# mysql -uroot -p¨verysafe¨ -S /data/mysqldata/3307/mysql.sock 

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 2

    Server version: 5.1.51-log Source distribution

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

    This software comes with ABSOLUTELY NO WARRANTY. This is free software,

    and you are welcome to modify and redistribute it under the GPL v2 license

    Type ¨help;¨ or ¨\h¨ for help. Type ¨\c¨ to clear the current input statement.

    mysql> 

通过这种方式,还可以非常轻松的创建第三、四....或更多数据库。当然了,如果是要同时创建多个新库的话,也许接下来用cp的方式会更快捷一些,不过这就跟mysql_install_db没什么关系了~~~