单机多实例- mysql
一般一个物理机上只跑一个mysql。单机多实例,就是让一台物理机上跑两个或更多个mysql。
虚拟软件:VMware-workstation10
操作系统:RedHatEnterpriseLinuxServer5.6-i386
内核 :2.6.18-238.el5
安装包: mysql.i386 0:5.0.77-4.el5_5.4 mysql-devel.i386 0:5.0.77-4.el5_5.4 mysql-server.i386 0:5.0.77-4.el5_5.4
依赖包:e2fsprogs-devel.i386 0:1.39-23.el5_5.1 keyutils-libs-devel.i386 0:1.2-1.el5
krb5-devel.i386 0:1.6.1-55.el5 libselinux-devel.i386 0:1.33.4-5.7.el5
libsepol-devel.i386 0:1.15.2-3.el5 openssl-devel.i386 0:0.9.8e-12.el5_5.7
perl-DBD-MySQL.i386 0:3.0007-2.el5 zlib-devel.i386 0:1.2.3-3
[root@localhost ~]# yum search mysql
[root@localhost ~]# yum install mysql.i386mysql-devel.i386mysql-server.i386 -y
[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql
mysql> show databases;
[root@localhost ~]# ps -aux |grep mysqld
[root@localhost ~]# service mysqld stop
[root@localhost ~]# cp -rp /var/lib/mysql /var/lib/mysql1 递归、权限一起copy
[root@localhost ~]# cp -rp /var/lib/mysql /var/lib/mysql2
[root@localhost ~]# cp -r /var/lib/mysql /var/lib/mysql3
[root@localhost ~]# service mysqld start
[root@localhost ~]# /usr/libexec/mysqld --datadir=/var/lib/mysql1--user=root--pid-file=
/var/run/mysqld/mysqld1.pid --socket=/var/lib/mysql/mysql1.sock --port=3307 &
[root@localhost ~]# /usr/libexec/mysqld --datadir=/var/lib/mysql2--user=root --pid-file=
/var/run/mysqld/mysqld2.pid --socket=/var/lib/mysql/mysql2.sock --port=3308 &
[root@localhost ~]# /usr/libexec/mysqld --datadir=/var/lib/mysql3--user=root --pid-file=
/var/run/mysqld/mysqld3.pid --socket=/var/lib/mysql/mysql3.sock--port=3309 &
[root@localhost ~]# ll /var/lib/mysql3
[root@localhost ~]# chown -R mysql.mysql /var/lib/mysql3上面没连权限一起拷,这里就要改配置文件的所有者、组。
[root@localhost ~]# /usr/libexec/mysqld --datadir=/var/lib/mysql3 --user=root
--psqld/mysqld3.pid --socket=/var/lib/mysql/mysql3.sock --port=3309 &
两种登陆mysql的方式:
[root@localhost ~]# mysql --socket=/var/lib/mysql/mysql.sock 基于soket
[root@localhost ~]# mysql --socket=/var/lib/mysql/mysql1.sock
[root@localhost ~]# mysql --socket=/var/lib/mysql/mysql2.sock
[root@localhost ~]# mysql --socket=/var/lib/mysql/mysql3.sock
[root@localhost ~]# mysql -h 127.0.0.1 -P 3306 基于port
[root@localhost ~]# mysql -h 127.0.0.1 -P 3307
[root@localhost ~]# mysql -h 127.0.0.1 -P 3308
[root@localhost ~]# mysql -h 127.0.0.1 -P 3309
本文出自 “8603154” 博客,请务必保留此出处http://8613154.blog.51cto.com/8603154/1387703