创建MySQL数据存放目录
- [root@ localhost data]# cd /data
- [root@localhost data]# mkdir mysql-3306
- [root@localhost data]# mkdir mysql-3307
- [root@localhost data]# chown mysql:mysql mysql-3306 mysql-3307 -R
- [root@localhost data]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql-3306 --basedir=/usr/local/mysql
- [root@localhost data]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql-3307 --basedir=/usr/local/mysql
- [root@localhost data]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
编辑my.cnf配置文件,添加/修改如下节点
- [root@localhost data]# vim /etc/my.cnf
- [mysqld_multi]
- mysqld = /usr/local/mysql/bin/mysqld_safe
- mysqladmin = /usr/local/mysql/bin/mysqladmin
- [mysqld3306]
- socket = /tmp/mysql-3306.sock
- port = 3306
- pid-file = /usr/local/mysql/var/mysql-3306.pid
- datadir = /data/mysql-3306
- [mysqld3307]
- socket = /tmp/mysql-3307.sock
- port = 3307
- pid-file = /usr/local/mysql/var/mysql-3307.pid
- datadir = /data/mysql-3307
启动MySQL
- [root@localhost data]# /etc/init.d/mysqld_multi start
- WARNING: my_print_defaults command not found.
- Please make sure you have this command available and
- in your path. The command is available from the latest
- MySQL distribution.
- ABORT: Can't find command 'my_print_defaults'.
- This command is available from the latest MySQL
- distribution. Please make sure you have the command
- in your PATH.
- [root@localhost data]# export PATH=/usr/local/mysql/bin:$PATH
- [root@localhost data]# /etc/init.d/mysqld_multi start
验证配置
- [root@localhost tmp]# /usr/local/mysql/bin/mysql -h127.0.0.1 -P3306
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 34
- Server version: 5.5.22-log Source distribution
- Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql> SHOW VARIABLES LIKE 'socket';
- +---------------+----------------------+
- | Variable_name | Value |
- +---------------+----------------------+
- | socket | /tmp/mysql-3306.sock |
- +---------------+----------------------+
- 1 row in set (0.00 sec)
- [root@localhost data]# /usr/local/mysql/bin/mysql -h127.0.0.1 -P3307
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 34
- Server version: 5.5.22-log Source distribution
- Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql> SHOW VARIABLES LIKE 'socket';
- +---------------+----------------------+
- | Variable_name | Value |
- +---------------+----------------------+
- | socket | /tmp/mysql-3307.sock |
- +---------------+----------------------+
- 1 row in set (0.00 sec)