源码库

MYSQL教程

源码库-建站教程-数据库教程-MYSQL教程- 正文

Centos中安装多个mysql数据的配置实例

2014-04-03 源码库 源码库 大字

注:本文档做了两个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
# wget


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的头文件到系统头文件

复制代码 代码如下:

分享到:

相关阅读

阅读排行

参与评论