MySQL Multi-instance configuration
Install MySQL5.5.32 from CentOS 6.8 above , we have finished compiling the installation, then configure multiple instances
5, add multi-instance Directory
[Email protected] application]# mkdir-p/data/{3306,3307}/data[[email protected] application]# tree/data//data/├──33 06│└──data└──3307└──data,
6. Uploading multi-instance configuration files
[Email protected]/]# CD/[[email protected]/]# rz-y data.zip [[email protected]/]# unzip Data.zip[[email protected]/ ]# Tree datadata├──3306 # #3306实例目录 │├──DATA│├──MY.CNF│└──MYSQL└──3307├──DATA├──MY.CNF └──mysql
# #多实例 file compared to the configuration file only string 3306 and 3307 , with the difference between ServerID
7. Add execute permission to MySQL startup script
Find/data-type f-name "MySQL" |xargs chmod +xchown-r Mysql.mysql/data
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/92/DE/wKiom1kEGjLzMo8JAABdjs04lcw923.png "style=" float : none; "title=" 1_ copy. png "alt=" Wkiom1kegjlzmo8jaabdjs04lcw923.png "/>
8, multi-instance initialization, the role is to load MySQL's own library and table # #
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# #提示:--basedir=/ application/mysql/is the installation path for MySQL,--datadir is the data file directory. Also, note that the path of mysql_install_db and MySQL5.1 is different, MySQL5.1 is not under the MySQL bin path.
Compile the process, note that there are 2 OK to be counted as successful
[[email protected] scripts]# ./mysql_install_db --basedir=/application/mysql -- datadir=/data/3306/data --user=mysqlwarning: the host ' DB02 ' could not be looked up with resolveip. this probably means that your libc libraries are not 100 % compatiblewith this binary MySQL version. The MySQL daemon, mysqld, should worknormally with the exception that host name Resolving will not work. this means that you should use ip addresses instead of hostnameswhen specifying mysql privileges ! Installing mysql system tables ... ok #<== Two OK is the sign of the success of the initialization. Filling help tables ... ok #<== Two OK is the sign of the success of the initialization. To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemplease remember to set a password for the mysql root user ! to do so, start the server, then issue the following commands:/application/mysql/bin/mysqladmin -u root password ' New-password '/application/ mysql/bin/mysqladmin -u root -h db02 password ' New-password ' Alternatively You can run:/application/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. this isstrongly recommended for Production servers. See the manual for more instructions. You can start the mysql&nbsP;daemon with:cd /application/mysql ; /application/mysql/bin/mysqld_safe &you can test the mysql daemon with mysql-test-run.plcd /application/mysql /mysql-test ; perl mysql-test-run.plplease report any problems with the /application/mysql/scripts/mysqlbug script!## #请注意如下几行英文的说明及报错New default config file was createdas /application/mysql//my.cnf andwill be used by Default by theserver when you start it. you may edit this file to changeserver settings# from the instructions above can guide MySQL's default configuration file has changed to /application/mysql//my.cnfwarning: default config file/etc/my.cnf exists on the systemThis file will be read by defaultby the MySQL Serverif you do not want to use this,either remove it, or use the--defaults-file argument tomysqld_safe when starting the server# you can see from the above description that the database is read/ETC/MY.CNF when it starts, so it may cause a failure to start, and the way to avoid this is to use Mysqld_ Safe starts the service with the--defaults-file parameter specifies the configuration file, the previous article has renamed/ETC/MY.CNF, so, there is no need to specify parameters, here is a pit, readers should pay attention to. This step must be initialized successfully, otherwise there will be a variety of issues such as not logging in to the database. [[email protected] ~]# mysqlerror1045 (28000): access denied for user ' root ' @ ' localhost ' (using password: no) Workaround: Reinitialize the database, which is typically a database initialization problem, or database file corruption, and directory permissions issues
Principle of 9,mysql initialization
The database is initialized with libraries and tables loaded in MySQL , such as the generated test and MySQL library tables.
After initializing the database, view the data directory, which files are generated
[[EMAIL&NBSP;PROTECTED]&NBSP;SCRIPTS]#&NBSP;LS&NBSP;-L&NBSP;/DATA/3306/DATA/TOTAL&NBSP;143372-RW-RW---- 1 &NBSP;MYSQL&NBSP;MYSQL&NBSP;134217728&NBSP;APR&NBSP;29&NBSP;03:32&NBSP;IBDATA1-RW-RW---- 1 mysql &NBSP;MYSQL&NBSP;&NBSP;&NBSP;4194304&NBSP;APR&NBSP;29&NBSP;03:32&NBSP;IB_LOGFILE0-RW-RW---- 1 mysql &NBSP;MYSQL&NBSP;&NBSP;&NBSP;4194304&NBSP;APR&NBSP;29&NBSP;03:32&NBSP;IB_LOGFILE1-RW-RW---- 1 mysql &NBSP;MYSQL&NBSP;&NBSP;&NBSP;4194304&NBSP;APR&NBSP;29&NBSP;03:32&NBSP;IB_LOGFILE2DRWX------ 2 mysql root 4096 Apr 29 03:31 mysql # #用于存放管理mysql数据drwx------ 2 mysql mysql 4096 Apr 29 03:31 performance_schema #内部性能库drwx------ 2 mysql root 4096 apr 29 03:31 test # #测试Library
10, start MySQL command multi-instance (3306/3307)
[[email protected] scripts]# /data/3306/mysql start # #启动脚本见百度云连接Starting mysql ... [[email protected] scripts]# /data/3307/mysql startstarting mysql ... [[email protected] scripts]# ps -ef|grep 330root 13426 1 0 11:32 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnfmysql 14150 13426 0 11:32 pts/1 00:00:05 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/ mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql -- Log-error=/data/3306/mysql_oldboy3306.err --open-files-limit=1024 --pid-file=/data/3306/mysqld.pid --socket=/data/3306/mysql.sock --port=3306root 17840 1 0 12:57 pts/1 00:00:00 /bin/sh / application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnfmysql 18540 17840 15 12:57 pts/1 00:00:01 /application/ mysql-5.5.32/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql -- datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/ data/3307/mysql_oldboy3307.err --open-files-limit=1024 --pid-file=/data/3307/mysqld.pid -- socket=/data/3307/mysql.sock --port=3307root 18558 1286 0 12:57 pts/1 00:00:00 grep --color=auto 330## If startup fails, check the log, where the path is an err file under Each instance, for example 3 below306[[email protected] scripts]# vi /data/3306/mysql_oldboy3306.err
11, connect MySQL database (in socket, multi-instance )
[[email protected] scripts]# mysql -uroot -p -s /data/3306/mysql.sock &NBSP;#-S Specifies the socket-bash: mysql: command not found #报错是因为没有设定环境变量解决方法的两种思路 to launch the instance: (second type recommended) 1) Add the mysql path to the environment variable echo "path= $PATH:/application/mysql/bin/" >>/etc/profilesource &NBSP;/ETC/PROFILEP2) mysql The file or script that needs to be executed and copy it to the first directory that already has the environment variable permission to execute. cp /application/mysql/bin/* /usr/local/sbin/Connect again, login 3306[[email protected] ~]# mysql -uroot -p -S /data/3306/mysql.sock [[email protected] ~]# mysql -uroot -p -s /data/3307/mysql.sockenter password: welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 2Server version: 5.5.32-log Source distributionCopyright (c) 2000, 2013, oracle and/or its&nbsP;affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or Itsaffiliates. other names may be trademarks of their respectiveowners . type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>
12, add power-on self-boot (multi-instance multi instances)
[[email protected] ~]# echo "# MySQL Multi instances" >>/etc/rc.local #添加注释, and instance startup items [[email protected] ~]# echo "/data /3306/mysql start ">>/etc/rc.local[[email protected" ~]# echo "/data/3307/mysql start" >>/etc/rc.loca
L
13, Troubleshooting Summary
MySQL multi-instance boot fault troubleshooting instructions
If the MySQL multi-instance service is not started, the exclusion method is as follows:
If you find that the MySQL corresponding instance port is not displayed, please wait a few seconds while checking that the MySQL service starts slightly slower
If that doesn't work, check the error log for your MySQL instance, which is defined at the bottom of the my.cnf configuration file:
For example: the error log for the 3306 instance is:/data/3306/*.err
Take a closer look at the screen output returned by all execution commands, and don't ignore the key output.
Auxiliary viewing system log/var/log/messages
If MySQL is associated with another service, check the related service log
READ carefully to see if the steps are correct, and write the commands and strings correctly.
Look at the log, a lot of summary, will eventually be called Master.
This article is from the "funny Brother Notes" blog, be sure to keep this source http://qiuyt.blog.51cto.com/1229789/1920687
CentOS 6.8 Compilation Installation MySQL5.5.32 (two multi-instance)