使用mysql_install_db mysql
先拷貝my.cnf到mysql2 mysql_install_db --basedir=/ --datadir=/usr/lib/mysql2/data/ --user=mysql
直接拷貝 sql
cp –f mysql mysql2 cp –f mysql mysql3 cp –f mysql mysql4 同時修改目錄權限 chown -R mysql mysql2
最後目錄結構以下 數據庫
如: socket
[client] #password = your_password port = 3309 socket = /var/lib/mysql4/mysql.sock [mysqld] port = 3309 socket = /var/lib/mysql4/mysql.sock pid-file=/var/lib/mysql4/db.pid datadir=/var/lib/mysql4 log-error=/var/lib/mysql4/db.err
啓動數據庫: spa
mysqld_safe --defaults-file=/var/lib/mysql/my.cnf --datadir=/var/lib/mysql4/ --pid-file=/var/lib/mysql4/db.pid mysqld_safe --defaults-file=/var/lib/mysql2/my.cnf --datadir=/var/lib/mysql4/ --pid-file=/var/lib/mysql4/db.pid mysqld_safe --defaults-file=/var/lib/mysql3/my.cnf --datadir=/var/lib/mysql4/ --pid-file=/var/lib/mysql4/db.pid mysqld_safe --defaults-file=/var/lib/mysql4/my.cnf --datadir=/var/lib/mysql4/ --pid-file=/var/lib/mysql4/db.pid
啓動後,效果如圖: .net
鏈接數據庫 code
mysql -uroot -proot --socket=/var/lib/mysql/mysql.sock mysql -uroot -proot --socket=/var/lib/mysql2/mysql.sock
mysqladmin --socket=/var/lib/mysql.sock -uroot -proot shutdown
首先建立一個mysqld_multi的/etc/mysql_multi.cnf文件 server
並配置各個數據庫的信息 blog
[mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin user = multi_admin password = 123456 # The MySQL server [mysqld1] socket = /tmp/mysql1.sock port = 3307 pid-file = /var/lib/mysql/mysql.sock pid-file = /var/lib/mysql/db.pid datadir = /var/lib/mysql user = mysql # The MySQL server [mysqld2] port = 3308 socket = /var/lib/mysql2/mysql.sock pid-file = /var/lib/mysql2/db.pid datadir = /var/lib/mysql2/ user = mysql 。。
啓動數據庫 get
mysqld_multi --config-file=/etc/mysql_multi.cnf start 1-2
中止數據庫
mysqld_multi --config-file=/etc/mysql_multi.cnf stop 1-2