我们先需要下载二进制的mysql包,假设安装在/usr/local/mysql002目录,/usr/local/mysql003目录,/usr/local/mysql004目录。 同一个服务器或vps安装多个mysql,设置不同端口。mysql002的配置过程如下,其他的也类似。
下载二进制mysql,mysql-xxxx-linux-xxx-glibc23.tar.gz 安装,
cd /usr/local/mysql002
scripts/mysql_install_db --user=mysql --no-defaults
vi /usr/local/mysql002/my.cnf
[mysqld]
port = 3002
socket = /tmp/mysql002.sock
basedir = /usr/local/mysql002
datadir=/usr/local/mysql002/data
pid-file=/usr/local/mysql002/data/mysql002.pid
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
skip-external-locking
./bin/mysqld_safe --defaults-file=./my.cnf --user=mysql &
./bin/mysqladmin --socket=/tmp/mysql002.sock -u root password 'mysql002root'
./bin/mysql --socket=/tmp/mysql002.sock -u root -pmysql002root
一个创建mysql003的范例:
tar -zxvf mysql-5.1.50-linux-x86_64-glibc23.tar.gz
mv mysql-5.1.50-linux-x86_64-glibc23 /usr/local/mysql003
cd /usr/local/mysql003
cp ../mysql002/my.cnf ./
chown -R mysql:mysql .
vi my.cnf (修改成对应的003路径)
scripts/mysql_install_db --user=mysql --no-defaults
./bin/mysqld_safe --defaults-file=./my.cnf --user=mysql &
./bin/mysqladmin --socket=/tmp/mysql003.sock -u root password 'mysql003root'
启动3个mysql的范例:
cd /usr/local/mysql001
./bin/mysqld_safe --defaults-file=./my.cnf --user=mysql &
cd /usr/local/mysql002
./bin/mysqld_safe --defaults-file=./my.cnf --user=mysql &
cd /usr/local/mysql003
./bin/mysqld_safe --defaults-file=./my.cnf --user=mysql &
停止mysql001范例:
cd /usr/local/mysql001
./bin/mysqladmin --socket=/tmp/mysql001.sock -uroot -pmysql001root shutdown
二进制是解压即可使用,无需卸载