Install configuration instances for multiple mysql Data in Centos

Source: Internet
Author: User

Note: This document provides two MYSQL instances, multiple instance methods, and so on.

LINUX: centOS6.3 64bit (default system development kit installed)
Database 1:
MYSQL version: mysql-5.0.56
PORT: 3306
System Directory:/usr/local/mysql3306
Database 2:
MYSQL version: mysql-5.1.72
PORT: 3307
System Directory:/usr/local/mysql3307

1. Install the SDK (use the default CENTOS update source ):
Copy codeThe Code is as follows: # yum-y install wget gcc-c ++ ncurses-devel cmake make perl bison openssl-devel gcc * libxml2 libxml2-devel curl-devel libjpeg * libpng * freetype *
Ii. Disable iptables and SELINUX
Copy codeThe Code is as follows: # service iptables stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
SELINUX = disabled
---------------
3. Install a mysql database instance
1. Download the compilation package:
Copy codeThe Code is 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. Initial Configuration before installation:
1) create a Mysql user
Copy codeThe Code is as follows: # useradd mysql
2) create data and log sub-directories under mysql
Copy codeThe Code is as follows: # mkdir/usr/local/mysql {3306, 3307}/data
# Mkdir/usr/local/mysql {3306, 3307}/log
3) modify the directory owner and group permissions
Copy codeThe Code is 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 a mysql directory and Configure permissions.
Copy codeThe Code is 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, compile, and install
Compile database 1:
Copy codeThe Code is 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-character er -- with-mysqld-ldflags =-all-static -- with-charset = utf8 -- with-extra-charsets = gbk- -extra-charsets = all -- with-plugins = csv, innobase, myisam, heap -- with-unix-socket-path =/tmp/mysql3306.sock
# Make
# Make install
Compile database 2:
Copy codeThe Code is 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-character er -- with-mysqld-ldflags =-all-static -- with-charset = utf8 -- with-extra-charsets = gbk- -extra-charsets = all -- with-plugins = csv, innobase, myisam, heap -- with-unix-socket-path =/tmp/mysql3307.sock
# Make
# Make install


4. Compile mysql configuration items:
Database 1 Configuration:
Copy codeThe Code is 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 = 256 M
Max_allowed_packet = 32 M
Table_cache = 3072
Thread _ cache_size = 256
Sort_buffer_size = 16 M
Read_buffer_size = 4 M
Read_rnd_buffer_size = 16 M
Net_buffer_length = 256 M
Thread_stack = 8 M
Query_cache_size = 128 M
Query_cache_limit = 2 M
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 2 Configuration:
Copy codeThe Code is 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 = 256 M
Max_allowed_packet = 32 M
Table_cache = 3072
Thread _ cache_size = 256
Sort_buffer_size = 16 M
Read_buffer_size = 4 M
Read_rnd_buffer_size = 16 M
Net_buffer_length = 256 M
Thread_stack = 8 M
Query_cache_size = 128 M
Query_cache_limit = 2 M
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 the mysql library file path to the system library file search path.
Method 1: directly create soft links
Copy codeThe Code is as follows: # ln-s/usr/local/mysql3306/lib/mysql/usr/lib/mysql
Method 2: Use ldconfig to import the system library
Copy codeThe Code is as follows: # echo "/usr/local/mysql3306/lib">/etc/ld. so. conf. d/mysql. conf
# Ldconfig
6. output the mysql header file to the system header file.
Copy codeThe Code is as follows: # ln-s/usr/local/mysql3306/include/mysql/usr/include/mysql
Note: you only need to add the database file of a mysql instance to the system database.

7. Enter the installation path of the corresponding instance and initialize the respective configuration scripts.
Database 1 Configuration:
Copy codeThe Code is as follows: # cd/usr/local/mysql3306
# Scripts/mysql_install_db -- user = mysql -- datadir =/usr/local/mysql3306/data
Database 2 Configuration:
Copy codeThe Code is 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 service directory and change the script configuration.
Copy codeThe Code is 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 1 Configuration:
Copy codeThe Code is as follows: # vi/etc/init. d/mysqld3006
Search for the following lines, marked in red as the added parameters:
---------------------------------------------
Copy codeThe Code is 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 2 Configuration:
Copy codeThe Code is as follows: # vi/etc/init. d/mysqld3007
Search for the following lines, marked in red as the added parameters:
---------------------------------------------
Copy codeThe Code is 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. configuration of system startup items
Database 1 Configuration:
Copy codeThe Code is as follows: # chkconfig -- add mysqld3306 # add a startup Service
# Chkconfig -- level 35 mysqld3306 on # Set mysql startup
Database 2 Configuration:
Copy codeThe Code is as follows: # chkconfig -- add mysqld3307
# Chkconfig -- level 35 mysqld3307 on
10. Start mysql
Database 1 startup:
Copy codeThe Code is as follows: # service mysqld3306 start
Database 2 startup:
Copy codeThe Code is as follows: # service mysqld3307 start
11 Add a mysql command set to the global variables of the system
Note: If the mysql client is not installed before, you can import the compiled mysql command set to the global variable of the system.
In the future, you can directly use the mysql command set without using the absolute path for access.
Copy codeThe Code is as follows: # echo "PATH = $ PATH:/usr/local/mysql3306/bin; export PATH">/etc/profile
# Source/etc/profile
12. Set the initial account and log on to the background:
Database 1:
Copy codeThe Code is as follows: #/usr/local/mysql3306/bin/mysqladmin-u root password 123456 # Set the super administrator password
#/Usr/local/mysql3306/bin/mysql-P3306-S/tmp/mysql3306.sock-uroot-p123456 # connect to the database

Database 2:
#/Usr/local/mysql3307/bin/mysqladmin-u root password 123456 # Set the super administrator password
#/Usr/local/mysql3307/bin/mysql-P3307-S/tmp/mysql3307.sock-uroot-p123456 # connect to the database

Note: because mysql environment variables are added, you can directly log on to the system background using the mysql Command. Here, the absolute path is used for standard operations.
# Mysql-P3307-S/tmp/mysql3307.sock-uroot-p123456

13. Port test:
Copy codeThe Code is as follows: # lsof-I: 3306
# Lsof-I: 3307

OK, all done!

Related Article

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.