1)创建数据文件所需的目录# mkdir -p /data/3308/data
# cp /data/3306/my.cnf /data/3308
# cp /data/3306/mysql /data/3308
2)配置权限# chown mysql.mysql /data/3308 -R
# chown root.root /data/3308/mysql
# chmod 700 /data/3308/mysql
3)修改数据配置文件及启动脚本# sed -i 's/3306/3308/g' /data/3308/my.cnf
# sed -i 's/server-id = 1/server-id = 8/g' /data/3308/my.cnf
# cat my.cnf | grep id
pid-file = /data/3308/mysql.pid
server-id = 8
pid-file=/data/3308/mysqld.pid
# sed -i 's/3306/3308/g' /data/3308/mysql
# cd /application/mysql/scripts/
# ./mysql_install_db --datadir=/data/3308/data --basedir=/application/mysql --user=mysql
# /data/3308/mysql start
Starting MySQL...
# echo $?
0
4)检查数据库的运行情况# netstat -tunlp | grep 330*
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4052/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 4048/mysqld
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 5502/mysqld
5)配置数据库开机自动启动# echo "/data/3308/mysql start">>/etc/rc.local
# tail -4 /etc/rc.local
显示的结果如下:
# mysql multi instances startup
/data/3306/mysql start
/data/3307/mysql start
/data/3308/mysql start
6)初始化数据库设置mysql初始密码:
# mysqladmin -u root -S /data/3308/mysql.sock password 'redhat12345'
# mysql -u root -S /data/3308/mysql.sock -predhat12345
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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.