0、在已创建mysql,port=3306的数据库前提下
需要删除/etc/.my.cnf再做以下操作 cp /etc/my.cnf /etc/my.cnf.3306
1、mkdir -p /u02/data/{3307,3308,3309}/data
2、chown -R mysql:mysql /u02/data/{3307,3308,3309}/data
3、创建/etc/my.cnf文件(多实例情况下的my.cnf)
[mysqld_multi] mysqld = /u02/app/mysql/bin/mysqld_safe mysqladmin = /u02/app/mysql/bin/mysqladmin #user = root #password ="root123" [mysqld3307] datadir = /u02/data/3307/data port = 3307 socket = /tmp/mysql3307.sock #log-bin = /u02/data/3307/data/mysql-bin pid-file = /u02/data/3307/data/mysql_3307.pid log-error=/var/log/3307.log [mysqld3308] datadir = /u02/data/3308/data port = 3308 socket = /tmp/mysql3308.sock #log-bin = /u02/data/3308/data/mysql-bin pid-file = /u02/data/3308/data/mysql_3308.pid log-error=/var/log/3308.log [mysqld3309] datadir = /u02/data/3309/data port = 3309 socket = /tmp/mysql3309.sock #log-bin = /u02/data/3309/data/mysql-bin pid-file = /u02/data/3309/data/mysql_3309.pid log-error=/var/log/3309.log
4.初始化,创建基础的数据库文件
mysqld --initialize-insecure --user=mysql --datadir=/u02/data/3307/data --basedir=/u02/app/mysql mysqld --initialize-insecure --user=mysql --datadir=/u02/data/3308/data --basedir=/u02/app/mysql mysqld --initialize-insecure --user=mysql --datadir=/u02/data/3309/data --basedir=/u02/app/mysql
5、启动多实例服务
mysqld_multi start --启动全部实例 mysqld_multi start 3307 --启动3307实例 mysqld_multi start 3308 --启动3308实例 start 3309 --启动3309实例 若同时起3306时,/etc/my.cnf已被3306使用,此时多实例为/etc/mysqld_multi.cnf,则登陆时为 mysqld_multti --defaults-extra-file=/etc/mysqld_multi.cnf start 3307
6、初始化密码
mysqladmin -uroot password root3307 -S /tmp/mysql3307.sock mysqladmin -uroot password root3308 -S /tmp/mysql3308.sock mysqladmin -uroot password root3309 -S /tmp/mysql3309.sock
7、登录
mysql -uroot -p -S /tmp/mysql3307.sock Enter password: root3307 mysql> select * from mysql.user; mysql>show databases;