# # #一: Preparation Environment:
Install the MySQL dependency package and check that the installation is complete
```
Yum?-y?install?? Ncurses-devel?libaio-devel?cmake
Rpm?-qa?? Ncurses-devel?libaio-devel?cmake
```
(2) Create a user to start MySQL
```
Useradd?-s?/sbin/nologin?-m?mysql
```
(3) Specification package installation path, and download decompression mysql-5.5.32 source Package
```
Mkdir?/home/oldboy/tools
Cd?/home/oldboy/tools
Wget?ftp://10.0.0.1/mysql-5.5.32.tar.gz
Tar?xf?mysql-5.5.32.tar.gz?
cd?mysql-5.5.32
```
# # #二: Compile and install MySQL source package
(1) Compile and install the MySQL source package using the CMake command
```
Cmake?-dcmake_install_prefix=/application/mysql-5.5.32?\
-dmysql_datadir=/application/mysql-5.5.32/data?\
-dmysql_unix_addr=/application/mysql-5.5.32/tmp/mysql.sock?\
-ddefault_charset=utf8?\
-ddefault_collation=utf8_general_ci?\
-dextra_charsets=gbk,gb2312,utf8,ascii?\
-denabled_loocal_infile=on?\
-dwith_innobase_storage_engine=1?\
-dwith_federated_storage_engine=1?\
-dwith_blackhole_storage_engine=1?\
-dwithout_example_storage_engine=1?\
-dwithout_parrtition_storage_engine=1?\
-dwith_fast_mutexes=1?\
-dwith_zlib=bundled?\
-denabled_local_infile=1?\
-dwith_readline=1?\
-dwith_embedded_server=1\
-dwith_debug=0
Echo?$?
```
(2) Steps to generate a makefile file install next
"' Shell
Make?&&?make?install
Echo?$?
```
(3) In this step our MySQL database is installed.
# # #三: Configure MySQL Database
(1) Create a soft link for the MySQL installation directory
"' Shell
Ln?-s?/application/mysql-5.5.32?/application/mysql
ll?/application/
```
(2) Create a MySQL multi-instance Directory
"' Shell
Mkdir?-p?/data/{3306,3307}/data
```
(3) Download MySQL multi-instance/data
"' Shell
cd?/home/oldboy/tools/
Wget?ftp://10.0.0.1/data.zip
Unzip?data.zip
cp?-r?data?/
tree?/data/
```
(4) Set up a multi-instance MySQL startup script to allow execution
"' Shell
Find?/data?-type?f?-name? " MySQL "|xargs?chmod?+x
Find?/data?-type?f?-name? " MySQL "|xargs?ls?-l
```
(5) Authorization management of Data directory of MySQL database
"' Shell
chown?-r?mysql.mysql?/data/
ll?/data/
```
(6) Initialization of MySQL database
"' Shell
cd?/application/mysql/scripts/
./mysql_install_db?--basedir=/application/mysql/?--datadir=/data/3306/data/?--user=mysql
./mysql_install_db?--basedir=/application/mysql/?--datadir=/data/3307/data/?--user=mysql
```
# # #四: MySQL multi-instance configuration and startup
(1) Start the first MySQL instance
"' Shell
/data/3306/mysql?start
```
(2) Start a second MySQL instance
"' Shell
/data/3307/mysql?start
```
(3) Start to complete check
"' Shell
netstat?-lntup|grep?330
```
(4) Copy the MySQL command to the specified sock directory
"' Shell
cp?/application/mysql/bin/*?/usr/local/sbin/
```
(5) Log in to the database using the MySQL command, you need to specify sock when logging in
"' Shell
Mysql?-uroot?-s?/data/3306/mysql.sock
Mysql?-uroot?-s?/data/3307/mysql.sock
```
(6) Setting up MySQL multi-instance database start-up
"' Shell
Echo? " Mysql?multi?instances "? >>/etc/rc.local
Echo? " /data/3306/mysql?start "? >>/etc/rc.local
Echo? " /data/3307/mysql?start "? >>/etc/rc.local
Tail?-n?3?/etc/rc.local
```
Common error problem exclusions:
(1) Whether to parse the host name
(2) Whether the permissions for the TMP directory are 1777
(3) If you start MySQL multi-instance without checking the port, wait a minute.
(4) Error logging through log. Err end
# # #五: How MySQL adds multiple instances
(1) Create a multi-instance storage directory
"' Shell
Mkdir?/data/3308/data?-p
```
(2) Copy an instance to the specified directory
"' Shell
\cp?/data/3306/{my.cnf,mysql}?/data/3308/
ll?/data/3308
```
(3) Be sure to back up the configuration file before modifying it
"' Shell
\cp?/data/3308/{my.cnf,my.cnf.source.bak}
\cp?/data/3308/{mysql,mysql.source.bak}
ll?/data/3308/
```
(4) Bulk change of MySQL configuration file and startup script using sed command
"' Shell
Sed?-i? ' S/3306/3308/g '?/data/3308/{my.cnf,mysql}
Sed?-i? ' s/server-id?=?1/server-id?=?8/ G '?/data/3308/my.cnf
```
(5) Set up 3308 DB instance owner for MySQL user
"' Shell
chown?-r?mysql.mysql?/data/3308/
ll?/data/3308/
```
(6) Set the permission for the third DB instance startup script to 700
"' Shell
Chmod?700?/data/3308/mysql
Ll?/data/3308/mysql
```
(7) Initializing database operations on the third DB instance
"' Shell
cd?/application/mysql/scripts/
./mysql_install_db?--basedir=/application/mysql/?--datadir=/data/3308/data/?--user=mysql
```
(8) Authorize MySQL startup script to have Execute permission
"' Shell
Chmod?+x?/data/3308/mysql
```
(9) Start a third instance of the database
"' Shell
/data/3308/mysql?start
```
(10) Start to complete check
"' Shell
netstat?-lntup|grep?330
```
(11) test whether the database can be accessed
"' Shell
Mysql?-s?/data/3308/mysql.sock
```
(12) Set the database settings to boot from
"' Shell
Echo? " /data/3308/mysql?start "? >>/etc/rc.local
Tail?-1?/etc/rc.local
```
# # #六: Because the password set in the script is Oldboy? So if we don't set it will not stop MySQL
"' Shell
Mysqladmin?password?oldboy?-s?/data/3306/mysql.sock
Mysqladmin?password?oldboy?-s?/data/3307/mysql.sock
Mysqladmin?password?oldboy?-s?/data/3308/mysql.sock
Mysql?-uroot?-poldboy123?-s?/data/3306/mysql.sock
```
# # #七: MySQL remote connection test
(1) Command use format
"' Shell
Mysql?-uroot?-poldboy?-h?10.0.0.52?-p port number?-P? for ports parameter
```
(2) Remote connection multi-instance database test
"' Shell
mysql?-uroot?-poldboy?-h?10.0.0.52?-p?3306
```
From for notes (Wiz)
List of attachments
Quick note 01-mysql installation and configuration of multiple instances