kider 发表于 2007-10-17 09:15:54

在同一台机启动多个MySQL服务

此功能给我带来的很大的方便,现在简要总结出来,以便给朋友们有所帮助。

在同一台机启动多个MySQL服务,多个服务可以是不同版本,同时运行。

以下给出一个简单的例子,只做个思路引导,在Linux平台中同时运行MySQL5.0和MySQL6.0两个服务,需要注意的是在安装时需要用MySQL的non RPM packages包的类型安装,方便安装到不同的目录中,可以从http://dev.mysql.com/downloads/mysql/5.0.html#linux得到下载包。


服务启动1、启动MySQL5.0(默认的方式,正常启动)

2、登陆MySQL5.0
# mysql -S /opt/lampp/var/mysql/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

3、启动MySQL6.0
# bin/mysqld_safe --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --socket=/tmp/my.sock --port=3307&
5237
# Starting mysqld daemon with databases from /usr/local/mysql/data

4、登陆MySQL6.0
# mysql -S /tmp/my.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 6.0.2-alpha MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 监控和查看MySQL运行情况1、查看进程
ps -ef|grep mysql
netstat -nl

2、查看端口
# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:858 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:852 0.0.0.0:*
udp 0 0 0.0.0.0:855 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
......远程登陆这两个MySQL服务的方法1、先在服务器上设置远程登陆的帐号及权限
mysql> grant all on *.* to 'root'@'%' identified by 'xxxx';
Query OK, 0 rows affected (0.02 sec)

2、远程登陆(需要任意MySQL客户端)
C:\>mysql -uroot -proot -h192.168.0.5 -P 3306
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.45

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


C:\>mysql -uroot -proot -192.168.0.5 -P 3307
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 6.0.2-alpha

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

kider 发表于 2007-11-12 12:08:17

如果服务器繁忙,可以用来部署负载均衡...

fire9 发表于 2008-3-24 12:55:23

zhanghuiyun0978 发表于 2008-11-25 16:07:53

页: [1]
查看完整版本: 在同一台机启动多个MySQL服务