mysql多实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql多实例相关的知识,希望对你有一定的参考价值。
一、安装环境
操作系统:CentOS release 6.6 (Final)(最小化安装)
mysql版本:mysql-5.5.32.tar.gz
cmake版本:cmake-2.8.7.tar.gz
二、安装基本依赖包
首先将yum源更改为国内的阿里yum源
[[email protected] ~]# yum install wget -y
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[[email protected] ~]# cd /etc/yum.repos.d
[[email protected] yum.repos.d]# yum makecache
安装基本包以及必备依赖包
[[email protected] ~]# yum install make gcc vim lrzsz tree ncurses-devel libaio-devel qt* -y
三、源码编译安装cmake和mysql
首先创建存放源码包的文件夹,养成良好的运维习惯
[[email protected] ~]# mkdir /server/tools -p
[[email protected] ~]# cd /server/tools
我是在真机上将源码包下载下来,然后通过rz上传到服务器指定存放目录。(secureCRT和Xshell均支持本地和远程服务器的上传和下载)
[[email protected] tools]# rz
解压cmake
[[email protected] tools]# tar -zxvf cmake-2.8.7.tar.gz
[[email protected] tools]# cd cmake-2.8.7
编译cmake
[[email protected] cmake-2.8.7]# ./configure
安装cmake
[[email protected] cmake-2.8.7]# gmake && gmake install
解压mysql
[[email protected] tools]# tar -zxvf mysql-5.5.32.tar.gz
[[email protected] tools]# cd mysql-5.5.32
创建mysql用户
[[email protected] mysql-5.5.32]# groupadd mysql
[[email protected] mysql-5.5.32]# useradd -g mysql -s /sbin/nologin -M mysql
编译mysql
[[email protected] mysql-5.5.32]# mkdir /application -p
cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 -DMYSQL_DATADIR=/application/mysql-5.5.32/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock -DEXTRA_CHARSETS=gbk.gb2312.utf8.ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
安装mysql
[[email protected] mysql-5.5.32]# make && make install
四、复制my.cnf
[[email protected] mysql-5.5.32]# cp /server/tools/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
五、软链接以及环境变量配置
[[email protected] mysql-5.5.32]# ln -s /application/mysql-5.5.32/ /application/mysql
[[email protected] mysql-5.5.32]# echo ‘PATH=/application/mysql/bin:$PATH‘ >>/etc/profile
[[email protected] mysql-5.5.32]# source /etc/profile
六、授权
[[email protected] mysql-5.5.32]# chown -R mysql.mysql /application/mysql/data/
[[email protected] mysql-5.5.32]# chmod -R 1777 /tmp/
七、创建mysql多实例的数据文件目录
[[email protected] mysql-5.5.32]# mkdir -p /data/{3306,3307}/data
[[email protected] mysql-5.5.32]# tree /data
八、创建mysql实例的配置文件my.cnf
[[email protected] 3306]# cp /server/tools/mysql-5.5.32/support-files/my-small.cnf my.cnf
[[email protected] 3307]# vim my.cnf
可以根据自己的需要对配置文件做设置(附件中有my.cnf)
[[email protected] 3306]# cp my.cnf /data/3307/
[[email protected] 3307]# sed -i ‘s#3306#3307#g‘ my.cnf
[[email protected] 3307]# vim my.cnf
将server-id改成3
[[email protected] 3307]# chown -R mysql.mysql /data/
九、初始化数据库
[[email protected] 3306]# cd /application/mysql/scripts/
[[email protected] scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
[[email protected] scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
看见两个OK就成功啦!
十、启动mysql多实例
[[email protected] scripts]# mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 > /dev/null &
[[email protected] scripts]# mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 > /dev/null &
可以自己编写mysql启动脚本(附件中有mysql启动脚本)
查看下mysql多实例是否生效,即查看3306和3307是否开启
[[email protected] scripts]# ss -ntulp|grep 330
十一、mysql启动脚本启动mysql
[[email protected] 3306]# chown mysql:mysql mysql
[[email protected] 3307]# chown mysql:mysql mysql
[[email protected] 3306]# chmod u+x mysql
[[email protected] 3307]# chmod u+x mysql
[[email protected] 3306]# /data/3306/mysql start
[[email protected] 3306]# /data/3307/mysql start
[[email protected] 3306]# ss -ntulp|grep 330
tcp LISTEN 0 128 *:3306 *:* users: (("mysqld",68932,13))
tcp LISTEN 0 128 *:3307 *:* users: (("mysqld",69710,13))
十二、多实例进入mysql配置
[[email protected] ~]# mysqladmin password oldboy123 -S /data/3306/mysql.sock
[[email protected] ~]# mysqladmin password oldboy456 -S /data/3307/mysql.sock
进入mysql
[[email protected] ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock
[[email protected] ~]# mysql -uroot -poldboy456 -S /data/3307/mysql.sock
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user,host from mysql.user;
+------+--------------------+
| user | host |
+------+--------------------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| | oldboy.example.com |
| root | oldboy.example.com |
+------+--------------------+
5 rows in set (0.00 sec)
本文出自 “IT” 博客,请务必保留此出处http://wang119.blog.51cto.com/9428009/1795618
以上是关于mysql多实例的主要内容,如果未能解决你的问题,请参考以下文章