This article is about using MySQL source to install MySQL and configure multiple instances with Mysqld_multi.
1, download the MySQL source installation version
To MySQL website to find the appropriate version of the download, this article is downloaded version 5.1
Copy Code code as follows:
Wget-c ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.60.tar.gz
2, decompression installation
Copy Code code as follows:
Tar-zxv-f mysql-5.1.60.tar.gz
./configure--prefix=/usr/local/mysql--with-charset=utf8
--with-extra-charset=all--enable-thread-safe-client--enable-assembler
--with-readline--with-big-tables
--with-named-curses-libs=/usr/lib/libncursesw.so.5
Make && make install
3. Add Users and user groups
Copy Code code as follows:
Groupadd MySQL #添加mysql用户组
useradd-g MySQL MySQL #创建mysql用户并把它放到mysql组下
Chown-r Root:mysql/usr/local/mysql #修改mysql文件属性
4, Initialization Data directory
Copy Code code as follows:
#把用到的工具添加到/usr/bin Directory
Ln-s/usr/local/mysql/bin/mysqld_multi/usr/bin/mysqld_multi
Ln-s/usr/local/mysql/bin/mysql_install_db/usr/bin/mysql_install_db
#初始化四个数据目录
mysql_install_db--DATADIR=/USR/LOCAL/VAR/MYSQL1--user=mysql
mysql_install_db--DATADIR=/USR/LOCAL/VAR/MYSQL2--user=mysql
mysql_install_db--datadir=/usr/local/var/mysql3--user=mysql
mysql_install_db--datadir=/usr/local/var/mysql4--user=mysql
#修改属性
Chown-r MYSQL/USR/LOCAL/VAR/MYSQL1
Chown-r MYSQL/USR/LOCAL/VAR/MYSQL2
Chown-r Mysql/usr/local/var/mysql3
Chown-r MYSQL/USR/LOCAL/VAR/MYSQL4
5. Configure multiple instance startup scripts
Copy from MySQL source to/etc/init.d/directory
Copy Code code as follows:
Cp/usr/local/src/mysql-5.1.60/support-files/mysqld_multi.server/etc/init.d/mysqld_multi.server
#修改basedir和bindir为安装路径
Basedir=/usr/local/mysql
Bindir=/usr/local/mysql/bin
6. Configure multiple instance database configuration files
Use the Mysqld_multi tool to view the template method for this profile, which is: Mysqld_multi--example
Create a file in the/etc/directory/etc/mysqld_multi.cnf, glue the Mysqld_multi--example the resulting files, and modify the corresponding attributes, such as: Mysqld,mysqladmin,socket,port, Pid-file,datadir,user and so on.
Copy Code code as follows:
[Mysqld_multi]
Mysqld =/usr/local/mysql/bin/mysqld_safe
Mysqladmin =/usr/local/mysql/bin/mysqladmin
#user = MySQL
#password = My_password
[Mysqld1]
Socket =/usr/local/var/mysql1/mysql1.sock
Port = 3306
Pid-file =/usr/local/var/mysql1/mysql1.pid
DataDir =/USR/LOCAL/VAR/MYSQL1
#language =/usr/local/mysql/share/mysql/english
user = MySQL
[Mysqld2]
Socket =/usr/local/var/mysql2/mysql2.sock
Port = 3307
Pid-file =/usr/local/var/mysql2/mysql2.pid
DataDir =/usr/local/var/mysql2
#language =/usr/local/mysql/share/mysql/english
user = MySQL
[MYSQLD3]
Socket =/usr/local/var/mysql3/mysql3.sock
Port = 3308
Pid-file =/usr/local/var/mysql3/mysql3.pid
DataDir =/usr/local/var/mysql3
#language =/usr/local/mysql/share/mysql/english
user = MySQL
[Mysqld4]
Socket =/usr/local/var/mysql4/mysql4.sock
Port = 3309
Pid-file =/usr/local/var/mysql4/mysql4.pid
DataDir =/usr/local/var/mysql4
#language =/usr/local/mysql/share/mysql/english
user = MySQL
7. Start multi-instance database
Copy Code code as follows:
Add/usr/local/mysql/bin to the $PATH environment variable.
Export Path=/usr/local/mysql/bin: $PATH
#查看数据库状态
Mysqld_multi--defaults-extra-file=/etc/mysqld_multi.cnf
#结果都为没有运行
Reporting MySQL Servers
MySQL server from Group:mysqld1 isn't running
MySQL server from Group:mysqld2 isn't running
MySQL server from group:mysqld3 isn't running
MySQL server from GROUP:MYSQLD4 isn't running
#启动
Mysqld_multi--defaults-extra-file=/etc/mysqld_multi.cnf Start
#结果为
Reporting MySQL Servers
MySQL server from Group:mysqld1 isn't running
MySQL server from Group:mysqld2 isn't running
MySQL server from group:mysqld3 isn't running
MySQL server from GROUP:MYSQLD4 isn't running
#启动具体某一个实例可在start, after the stop plus specific data 1,2,3, etc.
8, view the results of the operation
Copy Code code as follows:
#查看相应端口是否已经被监听
Netstat-tunlp
#查看是否有活动进程
Ps-aux|grep MySQL
9, login to the corresponding database
Copy Code code as follows:
#进入端口为3306的数据库
Mysql-uroot-p-h127.0.0.1-p3306
#通过sock文件登录
Mysql-uroot-p-s/usr/local/var/mysql1/mysql1.sock
#查看socket文件
Mysql> show VARIABLES like ' socket ';
#查看pid文件
Mysql> show VARIABLES like '%pid% ';