日期:2014-05-16  浏览次数:20693 次

linux 安装多个mysql5.5

?

目标:在服务器安装两个mysql5.5端口分别为3316和3326

?

// 添加mysq用户、l用户组

[root@test02 software]# groupadd mysql

[root@test02 software]# useradd -r -g mysql mysql

?

// 解压

[root@test02 software]# tar zxf mysql-5.5.22-linux2.6-i686.tar.gz

?

// 重命名

[root@test02 software]# mv mysql-5.5.22-linux2.6-i686 mysql-3316

?

// 进入到mysql 安装目录

[root@test02 software]# cd mysql-3316

?

?

// 改变权限

[root@test02 mysql-3316]# chown -R mysql:mysql .

?

// 初始化系统数据库

[root@test02 mysql-3316]# scripts/mysql_install_db --user=mysql

?

//修改配置文件中的端口号和socket文件位置,mysql中提供了多个配置文件模板,这里只修改support-files中的my-samll.cnf

// 将其中的3306改为3316,socket 改为 /tmp/mysql3316.sock

[root@test02 mysql-3316]# vim support-files/my-small.cnf

?

//运行mysql

[root@test02 mysql-3316]# ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql &

[1] 3724
[root@test02 mysql-3316]# 121031 14:12:40 mysqld_safe Logging to '/opt/software/mysql-3316/data/test02.err'.
121031 14:12:40 mysqld_safe Starting mysqld daemon with databases from /opt/software/mysql-3316/data

?

// 修改root密码,这里需要显示指定端口号和socket文件路径
[root@test02 mysql-3316]# ./bin/mysqladmin -u root -P 3316 -S /tmp/mysql3316.sock password '123456'

?

// 连接到数据库,这里需要显示指定端口号和socket文件路径

[root@test02 mysql-3316]# ./bin/mysql -u root -p? -P 3316 -S /tmp/mysql3316.sock
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

?

这样就安装完了,另一个端口为3326的数据库也按上面这样安装

?

?

[root@test02 mysql-3326]# ps aux|grep mysql
root????? 3335? 0.0? 0.1? 18592? 2028 pts/0??? S+?? 13:56?? 0:00 ./bin/mysql -uroot -p -P5188 -S/tmp/mysql3316.sock
root????? 3724? 0.0? 0.1? 63828? 1352 pts/1??? S??? 14:12?? 0:00 /bin/sh ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql
mysql???? 3939? 0.0? 3.0 321268 31472 pts/1??? Sl?? 14:12?? 0:00 /opt/software/mysql-3316/bin/mysqld --defaults-file=support-files/my-small.cnf --basedir=/opt/software/mysql-3316 --datadir=/opt/software/mysql-3316/data --plugin-dir=/opt/software/mysql-3316/lib/plugin --user=mysql --log-error=/opt/software/mysql-3316/data/test02.err --pid-file=/opt/software/mysql-3316/data/test02.pid --socket=/tmp/mysql3316.sock --port=3316
root????? 4021? 0.0? 0.1? 63828? 1352 pts/1??? S??? 14:18?? 0:00 /bin/sh ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql
mysql???? 4236? 0.1? 3.0 321400 31708 pts/1??? Sl?? 14:18?? 0:00 /opt/software/mysql-3326/bin/mysqld --defaults-file=support-files/my-small.cnf --basedir=/opt/software/mysql-3326 --datadir=/opt/software/mysql-3326/data --plugin-dir=/opt/software/mysql-3326/lib/plugin --user=mysql --log-error=/opt/software/mysql-3326/data/test02.err --pid-file=/opt/software/mysql-3326/data/test02.pid --socket=/tmp/mysql3326.sock --port=3326
root????? 4267? 0.0? 0.0? 61188?? 768 pts/1??? R+?? 14:19?? 0:00 grep mysql
[root@test02 mysql-3326]#

?

?

?

?

?

?

?

?

?

?

?

?

?