Centos中裝置多個mysql數據的設置裝備擺設實例。本站提示廣大學習愛好者:(Centos中裝置多個mysql數據的設置裝備擺設實例)文章只能為提供參考,不一定能成為您想要的結果。以下是Centos中裝置多個mysql數據的設置裝備擺設實例正文
注:本文檔做了兩個MYSQL實例,多個實例辦法以此類推
LINUX操作體系:centOS6.3 64bit(裝置了體系默許開辟包)
數據庫一:
MYSQL版本:mysql-5.0.56
PORT:3306
體系目次:/usr/local/mysql3306
數據庫二:
MYSQL版本:mysql-5.1.72
PORT:3307
體系目次:/usr/local/mysql3307
一.裝置開辟包(應用默許CENTOS更新源):
# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
二.封閉iptables和SELINUX
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------
三.裝置mysql數據庫實例
1.下載編譯包:
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
2.裝置前的初始設置裝備擺設任務:
1).創立一個Mysql用戶
# useradd mysql
2).新建mysql下data和log子目次
# mkdir /usr/local/mysql{3306,3307}/data
# mkdir /usr/local/mysql{3306,3307}/log
3).修正目次的所屬者和所屬組權限
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data
# chmod 750 /usr/local/mysql{3306,3307}/log
4).創立mysql相干目次並設置裝備擺設權限
# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc
3.解包編譯裝置
編譯數據庫一:
# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
# make
# make install
編譯數據庫二:
# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make
# make install
4.編寫mysql設置裝備擺設項:
數據庫一設置裝備擺設:
# vi /usr/local/mysql3306/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3306/data
socket=/tmp/mysql3306.sock
user=mysql
port=3306
pid-file=/var/lib/mysqld3306/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3306/log/error.log
log=/usr/local/mysql3306/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3306/log/slowquery.log
log-bin= /usr/local/mysql3306/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3306.log
pid-file=/var/run/mysqld3306/mysqld.pid
-------------------------------------------------------
數據庫二設置裝備擺設:
# vi /usr/local/mysql3307/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3307/data
socket=/tmp/mysql3307.sock
user=mysql
port=3307
pid-file=/var/lib/mysqld3307/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3307/log/error.log
log=/usr/local/mysql3307/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3307/log/slowquery.log
log-bin= /usr/local/mysql3307/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3307.log
pid-file=/var/run/mysqld3307/mysqld.pid
-------------------------------------------------------
5.將mysql的庫文件途徑參加體系的庫文件搜刮途徑中
辦法一:直接做軟鏈接
# ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql
辦法二:應用ldconfig導入體系庫
# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig
6.輸入mysql的頭文件到體系頭文件
# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql
注: 此處只需將一個mysql實例的庫文件添加到體系庫,無需屢次添加
7.進入響應實例的裝置途徑,初始化各自設置裝備擺設劇本
數據庫一設置裝備擺設:
# cd /usr/local/mysql3306
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data
數據庫二設置裝備擺設:
# cd /usr/local/mysql3307
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data
8.復制mysql啟動劇本到體系辦事目次,並更改劇本設置裝備擺設
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307
數據庫一設置裝備擺設:
# vi /etc/init.d/mysqld3006
搜刮以下行,白色標注的為添加的參數:
---------------------------------------------
basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data
conf=/usr/local/mysql3306/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
數據庫二設置裝備擺設:
# vi /etc/init.d/mysqld3007
搜刮以下行,白色標注的為添加的參數:
---------------------------------------------
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
9.體系啟動項相干設置裝備擺設
數據庫一設置裝備擺設:
# chkconfig --add mysqld3306 #添加開機啟動辦事
# chkconfig --level 35 mysqld3306 on #設置mysql啟動
數據庫二設置裝備擺設:
# chkconfig --add mysqld3307
# chkconfig --level 35 mysqld3307 on
10.啟動mysql
數據庫一啟動:
# service mysqld3306 start
數據庫二啟動:
# service mysqld3307 start
11 添加mysql敕令集到體系全局變量
注:假如體系之前未裝置mysql客戶端,可以將編譯好的mysql敕令集導入體系全局變量
今後便可以直接應用mysql敕令集,而不須要應用相對途徑拜訪.
# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile
# source /etc/profile
12. 設置初始賬戶,並上岸後台:
數據庫一:
# /usr/local/mysql3306/bin/mysqladmin -u root password 123456 #設置超等治理員暗碼
# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 #銜接數據庫
數據庫二:
# /usr/local/mysql3307/bin/mysqladmin -u root password 123456 #設置超等治理員暗碼
# /usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456 #銜接數據庫
注: 由於加了mysql情況變量,今後體系後台可以直接應用mysql敕令登錄,這裡應用相對途徑是為了標准操作
# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456
13.端口測試:
#lsof -i:3306
#lsof -i:3307
OK,年夜功樂成!