MySQL社区

标题: 在同一台机启动多个MySQL服务 [打印本页]

作者: kider    时间: 2007-10-17 09:15
标题: 在同一台机启动多个MySQL服务
此功能给我带来的很大的方便,现在简要总结出来,以便给朋友们有所帮助。

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

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


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

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

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

  8. mysql>

  9. 3、启动MySQL6.0
  10. [root@MyWebsite mysql]# bin/mysqld_safe --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --socket=/tmp/my.sock --port=3307&
  11. [1] 5237
  12. [root@MyWebsite mysql]# Starting mysqld daemon with databases from /usr/local/mysql/data

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

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

  19. mysql>
复制代码
监控和查看MySQL运行情况
  1. 1、查看进程
  2. ps -ef|grep mysql
  3. netstat -nl

  4. 2、查看端口
  5. [root@MyWebsite mysql]# netstat -nl
  6. Active Internet connections (only servers)
  7. Proto Recv-Q Send-Q Local Address Foreign Address State
  8. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
  9. tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN
  10. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
  11. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
  12. tcp 0 0 0.0.0.0:858 0.0.0.0:* LISTEN
  13. tcp 0 0 :::22 :::* LISTEN
  14. udp 0 0 0.0.0.0:68 0.0.0.0:*
  15. udp 0 0 0.0.0.0:852 0.0.0.0:*
  16. udp 0 0 0.0.0.0:855 0.0.0.0:*
  17. udp 0 0 0.0.0.0:111 0.0.0.0:*
  18. udp 0 0 0.0.0.0:631 0.0.0.0:*
  19. ......
复制代码
远程登陆这两个MySQL服务的方法
  1. 1、先在服务器上设置远程登陆的帐号及权限
  2. mysql> grant all on *.* to 'root'@'%' identified by 'xxxx';
  3. Query OK, 0 rows affected (0.02 sec)

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

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

  9. mysql>


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

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

  14. mysql>
复制代码

作者: kider    时间: 2007-11-12 12:08
如果服务器繁忙,可以用来部署负载均衡...
作者: fire9    时间: 2008-3-24 12:55
提示: 作者被禁止或删除 内容自动屏蔽
作者: zhanghuiyun0978    时间: 2008-11-25 16:07
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2