Linux下搭建MySQL多实例环境

页面导航:首页 > 数据库 > Mysql > Linux下搭建MySQL多实例环境

Linux下搭建MySQL多实例环境

来源: 作者: 时间:2016-02-04 09:03 【

Linux下搭建MySQL多实例环境前置条件:安装cmake工具、gcc工具gcc一般的linux环境都已经安装,现在安装cmake[[email protected] workspace] wget http: www cmake org files v2 8 cmake-2 8 3 tar gz[[email protected]
Linux下搭建MySQL多实例环境
 
前置条件:安装cmake工具、gcc工具
 
gcc一般的linux环境都已经安装,现在安装cmake
 
[[email protected] workspace]# wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
 
[[email protected] workspace]# tar xvf cmake-2.8.3.tar.gz
 
[[email protected] workspace]# cd cmake-2.8.3
 
[[email protected] workspace]# ./configure
 
[[email protected] workspace]# make & make install
 
mysql包
 
[[email protected] workspace]# wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.32.tar.gz
 
[[email protected] workspace]# tar xvf mysql-5.5.32.tar.gz
 
[[email protected] workspace]# cd mysql-5.5.32
 
安装第一个MySQL
 
(1)创建所需要的文件目录
 
[[email protected] local]# cd /usr/local/
 
[[email protected] local]# mkdir
 
[[email protected] local]# cd mysql/
 
[[email protected] mysql]# mkdir data
 
[[email protected] mysql]# mkdir etc
 
(2)配置MySQL源码编译选项
 
[[email protected] mysql-5.5.32]# cmake                     \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    \
> -DMYSQL_DATADIR=/usr/local/mysql/data          \
> -DSYSCONFDIR=/usr/local/mysql/etc                   \
> -DWITH_MYISAM_STORAGE_ENGINE=1          \
> -DWITH_INNOBASE_STORAGE_ENGINE=1      \
> -DWITH_MEMORY_STORAGE_ENGINE=1        \
> -DWITH_READLINE=1                                          \
> -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock         \
> -DMYSQL_TCP_PORT=3306                               \
> -DENABLED_LOCAL_INFILE=1                           \
> -DWITH_PARTITION_STORAGE_ENGINE=1     \
> -DEXTRA_CHARSETS=all                                    \
> -DDEFAULT_CHARSET=utf8                               \
> -DDEFAULT_COLLATION=utf8_general_ci
 
(3)编译安装
 
[[email protected] mysql-5.5.32]# make & make install
 
(4)配置第一个MySQL实例
 
[[email protected] mysql-5.5.32]# cd /usr/local/mysql
 
[[email protected] mysql]# chown -R mysql:mysql .
 
[[email protected] mysql]# cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
 
[[email protected] mysql]# vi /usr/local/mysql/etc/my.cnf
 
添加 datadir=/usr/local/mysql/data
        default-storage-engine=MyISAM
 
[[email protected] mysql]# cd /usr/local/mysql/scripts/
 
[[email protected] scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &
 
[[email protected] bin]# cd /usr/local/mysql/bin
 
[[email protected] bin]# ./mysqld_safe --user=root
[1] 28869
[[email protected] bin]# 131016 20:07:13 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
131016 20:07:14 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
 
查看服务是否启动成功
 
[[email protected] bin]# netstat -tlnap | grep mysql
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      29147/mysqld
 
登录MySQL并修改root用户密码
 
[[email protected] bin]# ./mysqladmin -uroot password 'eisoo.com'
 
[[email protected] bin]# ./mysql -uroot -peisoo.com
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32-log Source distribution
 
Copyright (c) 2000, 2013, 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> exit
 
安装第二个MySQL数据库
 
(1)清理配置信息
 
[[email protected] bin]# cd /workspace/mysql-5.5.32
[[email protected] mysql-5.5.32]# make clean
[[email protected] mysql-5.5.32]# rm -rf CMakeCache.txt
 
(2)创建所需要的文件目录
 
[[email protected] mysql-5.5.32]# cd /usr/local/
 
[[email protected] local]# mkdir mysql3307
 
[[email protected] local]# cd mysql3307/
 
[[email protected] mysql3307]# mkdir data
 
[[email protected] mysql3307]# mkdir etc
 
(3)配置第二个实例的编译信息
 
[[email protected] bin]# cd /workspace/mysql-5.5.32
 
[[email protected] mysql-5.5.32]# cmake                     \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307    \
> -DMYSQL_DATADIR=/usr/local/mysql3307/data          \
> -DSYSCONFDIR=/usr/local/mysql3307/etc                   \
> -DWITH_MYISAM_STORAGE_ENGINE=1          \
> -DWITH_INNOBASE_STORAGE_ENGINE=1      \
> -DWITH_MEMORY_STORAGE_ENGINE=1        \
> -DWITH_READLINE=1                                          \
> -DMYSQL_UNIX_ADDR=/tmp/mysqld3307.sock         \
> -DMYSQL_TCP_PORT=3307                               \
> -DENABLED_LOCAL_INFILE=1                           \
> -DWITH_PARTITION_STORAGE_ENGINE=1     \
> -DEXTRA_CHARSETS=all                                    \
> -DDEFAULT_CHARSET=utf8                               \
> -DDEFAULT_COLLATION=utf8_general_ci
 
(4)编译安装
 
[[email protected] mysql-5.5.32]# make & make install
 
(5)配置第二个MySQL实例
 
[[email protected] mysql-5.5.32]# cd /usr/local/mysql3307
 
[[email protected] mysql3307]# chown -R mysql:mysql .
 
[[email protected] mysql3307]# cp support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf
 
[[email protected] mysql3307]# vi /usr/local/mysql3307/etc/my.cnf
 
添加 datadir=/usr/local/mysql3307/data
        default-storage-engine=MyISAM
 
[[email protected] mysql3307]# cd /usr/local/mysql3307/scripts/
 
[[email protected] scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql3307 --datadir=/usr/local/mysql3307/data &
 
[[email protected] scripts]# cd /usr/local/mysql3307/bin
 
[[email protected] bin]# ./mysqld_safe --user=root
 
131016 20:40:27 mysqld_safe Logging to '/usr/local/mysql3307/data/localhost.localdomain.err'.
131016 20:40:27 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql3307/data
 
查看服务是否启动成功
 
[[email protected] bin]# netstat -tlnap | grep mysql
 
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      29147/mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      7447/mysqld
 
登录MySQL并修改root用户密码
 
[[email protected] bin]# ./mysqladmin -uroot password 'eisoo.com123'
 
[[email protected] bin]# ./mysql -uroot -peisoo.com123
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32-log Source distribution
 
Copyright (c) 2000, 2013, 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> exit
 
增加环境变量
 
[[email protected] /]# vi /etc/profile
 
增加一行:export PATH=/usr/local/mysql/bin:/usr/local/mysql3307/bin:$PATH
 
[[email protected] /]# source /etc/profile
 
[[email protected] /]# export $PATH
 
分别启动不同实例:
 
[[email protected] /]# mysqld_safe --user=root --port=3306 --socket=/tmp/mysqld.sock --datadir=/usr/local/mysql/data &
 
[[email protected] /]# mysqld_safe --user=root --port=3307 --socket=/tmp/mysqld3307.sock --datadir=/usr/local/mysql3307/data &
 
分别登陆不同实例:
 
[[email protected] /]# mysql -uroot -peisoo.com -S /tmp/mysqld.sock
[[email protected] /]# mysql -uroot -peisoo.com123 -S /tmp/mysqld3307.sock
 
启动还是太麻烦,可以这样做:
 
[[email protected] /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql3306
[[email protected] /]# cp /usr/local/mysql3307/support-files/mysql.server /etc/init.d/mysql3307
 
给mysql用户添加权限:
 
[[email protected] /]# chmod -R 755 /usr/local/mysql/data
[[email protected] /]# chmod -R 755 /usr/local/mysql/data
 
分别启动实例对应的服务:
 
[[email protected] tmp]# service mysql3306 start
Starting MySQL.                                            [确定]
[[email protected] tmp]# service mysql3307 start
Starting MySQL.                                            [确定]
 
查看服务:
 
[[email protected] tmp]# netstat -tlnap | grep mysql
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      10759/mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      11097/mysqld
 
将服务添加到系统服务中,使其开机自动启动。
 
[[email protected] /]# chkconfig --add mysql3306
[[email protected] /]# chkconfig --add mysql3307
 
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<