首页 > 代码库 > Mysql多实例安装
Mysql多实例安装
前言:前文已经介绍单实例的安装,我们接着进行Mysql的多实例安装,我们利用多个配置文件,多个启动文件管理多实例
一、安装依赖包
yum install ncurses-devel libaio-devel gcc gcc-c++ cmake perl
下载Mysql安装包,下载地址mysql-5.5安装包,并解压安装包
tar -zxvf mysql-5.5.32.tar.gz cd mysql-5.5.32
编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_EXAMPLE_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITH_FAST_MUTEXES=1 \-DWITH_ZLIB=bundled \-DENABLED_LOCAL_INFILE=1 \-DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock-DENABLED_LOCAL_INFILE=ON -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 make && make install
二、配置用户权限
设置Mysql用户和组
groupadd mysql useradd -g mysql mysql
新建Mysql安装目录和数据文件目录
mkdir -p /usr/local/mysql mkdir -p /data/3306 mkdir -p /data/3307
修改目录所有者和组
chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /data/3306 chown -R mysql:mysql /data/3307
三、初始化数据库,配置配置文件,配置启动文件等
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3306/data --user=mysql /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3307/data --user=mysql
创建多个配置文件
vim /data/3306/my.cnf [client] port = 3306 socket = /data/3306/mysql.sock [mysqld] port = 3306 socket = /data/3306/mysql.sock basedir = /usr/local/mysql datadir = /data/3306/data skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M skip-name-resolve log-bin=mysql-bin binlog_format=mixed max_binlog_size = 500M server-id = 1 [mysqld_safe] log-error=/data/3306/ilanni.err pid-file=/data/3306/ilanni.pid [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
拷贝一份给3307,幷打文件里的3306都替换为3307
cp /data/3306/my.cnf /data/3307/my.cnf sed -i ‘s/3306/3307/g‘ /data/3307/my.cnf
创建Mysql服务启动脚本
vim /data/3306/mysqld #!/bin/bash mysql_port=3306 mysql_username="admin" mysql_password="password" function_start_mysql() { printf "Starting MySQL...\n" /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/${mysql_port}/my.cnf 2>&1 > /dev/null & } function_stop_mysql() { printf "Stoping MySQL...\n" /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/${mysql_port}/mysql.sock shutdown } function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql function_start_mysql } function_kill_mysql() { kill -9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘) kill -9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘) } case $1 in start) function_start_mysql;; stop) function_stop_mysql;; kill) function_kill_mysql;; restart) function_stop_mysql function_start_mysql;; *) echo "Usage: /data/${mysql_port}/mysqld {start|stop|restart|kill}";; esac
拷贝给3307一份启动脚本,把里面的3306都改为3307,幷赋予启动权限
cp /data/3306/mysqld /data/3307/mysqld sed -i ‘s/3306/3307/g‘ /data/3307/mysqld chmod +x /data/3306/mysqld chmod +x /data/3307/mysqld
修改/etc/profile文件,末尾添加PATH
PATH=/usr/local/mysql/bin:$PATH export PATH
保存修改,让配置立即生效
source /etc/profile
四,启动数据库幷登录
/data/3306/mysqld start /data/3307/mysqld start mysql -uroot -p -S /data/3306/mysql.sock mysql -uroot -p -S /data/3307/mysql.sock
本文出自 “数据库学习历程” 博客,请务必保留此出处http://yuemu.blog.51cto.com/10688235/1868201
Mysql多实例安装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。