CentOS a configuration instance where multiple Mysql data is installed _mysql

Source: Internet
Author: User
Tags chmod mkdir mysql client mysql version openssl iptables

Note: This document has two MySQL instances, multiple instance methods and so on

Linux operating system: centOS6.3 64bit (Installation of the system default development package)
Database one:
MySQL version: mysql-5.0.56
port:3306
System catalog:/usr/local/mysql3306
Database two:
MySQL version: mysql-5.1.72
port:3307
System catalog:/usr/local/mysql3307

I. Installing the development pack (using the default CentOS update source):

Copy Code code as follows:
# yum-y Install wget gcc-c++ ncurses ncurses-devel cmake make Perl bison OpenSSL openssl-devel gcc* libxml2 Curl-devel libjpeg* libpng* freetype*

Two. Close Iptables and SELinux
Copy Code code as follows:
# Service Iptables Stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
Selinux=disabled

---------------
Three. Install MySQL database instance
1. Download Compilation Package:
Copy Code code as follows:
# 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. Pre-installation Initial configuration work:
1). Create a MySQL user
Copy Code code as follows:
# useradd MySQL

2). New MySQL under Data and log subdirectories
Copy Code code as follows:
# Mkdir/usr/local/mysql{3306,3307}/data
# Mkdir/usr/local/mysql{3306,3307}/log

3). Modify the owner of the directory and the permissions of the group to which it belongs
Copy Code code as follows:
# 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. Create MySQL-related directories and configure permissions
Copy Code code as follows:
# 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. Unpack and compile the installation
Compile database one:
Copy Code code as follows:
# 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

Compile database two:
Copy Code code as follows:
# 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. Write MySQL configuration entries:
Database One configuration:

Copy Code code as follows:
# 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

-------------------------------------------------------
Database Two configuration:
Copy Code code as follows:
# 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. Add MySQL library file path to the system's library file search path
Method One: Make soft link directly

Copy Code code as follows:
# ln-s/usr/local/mysql3306/lib/mysql/usr/lib/mysql

Method Two: Use Ldconfig to import system library
Copy Code code as follows:
# echo "/usr/local/mysql3306/lib" >>/etc/ld.so.conf.d/mysql.conf
# Ldconfig

6. Output MySQL header file to system header file
Copy Code code as follows:
# ln-s/usr/local/mysql3306/include/mysql/usr/include/mysql

Note: Only one MySQL instance's library file can be added to the system library here without having to add multiple

7. Enter the installation path of the corresponding instance, initialize the respective configuration script
Database One configuration:

Copy Code code as follows:
# cd/usr/local/mysql3306
# scripts/mysql_install_db--user=mysql--datadir=/usr/local/mysql3306/data

Database Two configuration:
Copy Code code as follows:
# cd/usr/local/mysql3307
# scripts/mysql_install_db--user=mysql--datadir=/usr/local/mysql3307/data

8. Copy the MySQL startup script to the System services directory and change the script configuration
Copy Code code as follows:
# cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld3306
# cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld3307

Database One configuration:
Copy Code code as follows:
# vi/etc/init.d/mysqld3006

Search for the following line with the added parameters in red:
---------------------------------------------
Copy Code code as follows:
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 &
--------------------------------------------

Database Two configuration:
Copy Code code as follows:
# vi/etc/init.d/mysqld3007

Search for the following line with the added parameters in red:
---------------------------------------------
Copy Code code as follows:
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. System Startup Item related configuration
Database One configuration:

Copy Code code as follows:
# chkconfig--add mysqld3306 #添加开机启动服务
# chkconfig--level mysqld3306 on #设置mysql启动

Database Two configuration:
Copy Code code as follows:
# chkconfig--add mysqld3307
# chkconfig--level mysqld3307 on

10. Start MySQL
Database One start:
Copy Code code as follows:
# service mysqld3306 Start

Database two starts:
Copy Code code as follows:
# service mysqld3307 Start

11 add MySQL command set to system global variable
Note: If the MySQL client is not installed before the system, you can import the compiled MySQL command set into the system global variable
You can then use the MySQL command set directly, without the need to use absolute path access.
Copy Code code as follows:
# echo "path= $PATH:/usr/local/mysql3306/bin;export PATH" >>/etc/profile
# Source/etc/profile

12. Set up the initial account, and login backstage:
Database one:
Copy Code code as follows:
#/usr/local/mysql3306/bin/mysqladmin-u root password 123456 #设置超级管理员密码
#/usr/local/mysql3306/bin/mysql-p3306-s/tmp/mysql3306.sock-uroot-p123456 #连接数据库

Database two:
#/usr/local/mysql3307/bin/mysqladmin-u root password 123456 #设置超级管理员密码
#/usr/local/mysql3307/bin/mysql-p3307-s/tmp/mysql3307.sock-uroot-p123456 #连接数据库

Note: Because of the MySQL environment variable, the system can be used directly in the background of the MySQL command login, where the absolute path is used to standardize the operation
# mysql-p3307-s/tmp/mysql3307.sock-uroot-p123456

13. Port test:

Copy Code code as follows:
#lsof-i:3306
#lsof-i:3307

OK, that's it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.