In-depth analysis of mysql multi-instance installation based on bitsCN.com
I believe most people have encountered too many instances to install mysql. I believe most people only need to find a multi-instance installation tutorial and it will be easy to solve, but the more smooth the installation process, the more disturbing we are. why do you know the purpose of each sentence when we follow the tutorial step by step? What should we do after an error occurs? Now I am going to show you how to install it.
First, describe a scenario: My computer is a ubuntu system, and mysql has been automatically installed by apt-get before. This is one of the most common causes of errors.
The following is my installation process, which is filled with various errors:
6. mkdir mysql
7. groupadd mysql
8. useradd-r-g mysql
# Make clean
# Rm-f CMakeCache.txt
# Rm-rf/etc/my. cnf
9. cmake.-DCMAKE_INSTALL_PREFIX =/usr/local/mysql
-DMYSQL_DATADIR =/usr/local/mysql/data-DDEFAULT_CHARSET = utf8
-DDEFAULT_COLLATION = utf8_general_ci-DEXTRA_CHARSETS = all
-DENABLED_LOCAL_INFILE = 1
Make
Make install
This indicates that the installation of mysql source code has been completed. now we need to initialize the user, that is, the most important part of multiple instances, pay attention to the result after command execution in each step in the future:
Cd/usr/local/mysql
Chown-R root: mysql.
Chown-R mysql: mysql data
11. cp support-files/my-medium.cnf/etc/my. cnf
12. cd/usr/local/mysql
Scripts/mysql_install_db
-- Defaults-file =/usr/local/mysql/data_3308/my. cnf
-- Datadir =/usr/local/mysql/data_3308/
The above mysql_install_db command is used to initialize a new user. Pay attention to the result after command execution. The first execution result is as follows:
Root @ zhou:/usr/local/mysql # scripts/mysql_install_db -- defaults-file =/usr/local/mysql/data_3307/my. cnf -- datadir =/usr/local/mysql/data_3307/
Installing MySQL system tables...
130107 10:25:47 [ERROR] COLLATION 'latin1 _ swedish_ci 'is not valid for character set 'utf8'
130107 10:25:47 [ERROR] Aborting
130107 10:25:47 [Note]/usr/local/mysql/bin/mysqld: Shutdown complete
Here we can see that there has been an error. what is the cause? you should be able to understand it. you are so careless. This causes you to execute cmake again.
Then run the preceding command again. Until we see this result: the initialization is successful. Congratulations, you can perform the following operations.
Root @ zhou:/usr/local/mysql # mysql_install_db -- user = mysql -- defaults-file =/usr/local/mysql/data3307/my. cnf -- datadir =/usr/local/mysql/data3307/
Installing MySQL system tables...
OK
Filling help tables...
OK
At this time, he will generate some basic information such as mysql library and test library in our data directory.
By the way, you must pay attention to the fact that, when assigning permissions, mysql will not be able to read relevant files without caution.
Mysqld_safe -- defaults-file =/usr/local/mysql/data_3307/my. cnf &
130107 13:35:36 [Note] Server socket created on IP: '0. 0.0.0 '.
130107 13:35:36 [ERROR]/usr/local/mysql/bin/mysqld: Can't find file: './mysql/host. frm' (errno: 13)
130107 13:35:36 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host. frm' (errno: 13)
130107 13:35:36 mysqld_safe mysqld from pid file/usr/local/mysql/data3307/mysql. pid ended
The error is also obvious because we did not read the host. There are two ways to remedy frm permissions: one is to attach such permissions to mysql directly under the Directory, and the other is to investigate why it is like that? The reason is that we did not add the -- user = mysql parameter during initialization, resulting in the full-City root permission of the generated file. In this way, we need the following command next time:
Root @ zhou:/usr/local/mysql # mysql_install_db -- user = mysql -- defaults-file =/usr/local/mysql/data3307/my. cnf -- datadir =/usr/local/mysql/data3307/-- user = mysql
OK. Then we can run the command to check the number of services we have activated, and then log on to the system to perform basic operations, permissions, key tables, and replication.
After starting three mysql servers, I found that I could only log on to the service above 3306, but I couldn't log on. when I killed 3307 3306, an error occurred while logging on to mysql,
Root @ zhou:/usr/local/mysql/tmp # mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql. sock' (111)
The cause of the error is that when I didn't specify the database server, it had a default startup plan, so we can see that it was still waiting for the server of mysql 3306.
Root @ zhou:/etc/init. d # mysql-h127.0.0.1-P3307
BitsCN.com