Install mysql5.6.15 on centos6.3 and set mysql master-slave replication CentOS6CentOS
BitsCN.com
I. minimal installation of centos II. after the virtual machine is installed, iptables is automatically enabled and chkconfig iptables is permanently disabled. set static IP address for later shell connection, mysql master server 192.168.1.41, from the server 192.168.1.42; 1.vi/etc/sysconfig/network-scripts/ifcfg-eth0 (depending on the virtual machine Nic, here, eth0 may also be eth1, eth2) DEVICE = eth0 BOOTPROTO = static HWADDR = 00: 26: 18: 0B: 38: c0 ONBOOT = yes IPADDR = 192.168.1.41 NETMASK = 255.255.255.0 GATEWAY = 192.168.1.1 2. IP effective:/sbin/ifdown eth0/sbin/ifup eth0 3. notify gateway to update information:/etc/init . D/network restart 4. configure DNS: vi/etc/resolv. conf nameserver 202.101.172.35 5. chattr + I/etc/resolv. change conf to read-only 6. restart System 4 use shell to log on to 192.168.1.41 (mysql master server, first set one, then copy, clone, and generate from the service area) 5 install mysql5.6.15 (download the source code package from mysql.com on the official website for installation. Http://dev.mysql.com/downloads/mysql/) 1. install the tools and libraries required to compile the source code yum install gcc-c ++ ncurses-devel perl install cmake (after mysql5.5 are installed with cmake)
Wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
Tar-xzvf cmake-2.8.10.2.tar.gz
Cd cmake-2.8.10.2
./Bootstrap; make install
2. create a mysql user and group groupadd mysql
Useradd-r-g mysql
3. create a new mysql installation directory and Data Directory
Mkdir-p/usr/local/mysql
Mkdir-p/data/mysqldb
4. download the mysql source code package and decompress it for installation.
Find in the official website http://dev.mysql.com/downloads/mysql/, usually the last source code about 32 m
Tar-zxv-f mysql-5.6.15.tar.gz
5. install mysql
Cd mysql-5.6.15
Configure compilation information
Cmake/-DCMAKE_INSTALL_PREFIX =/usr/local/mysql/-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock/-DDEFAULT_CHARSET = utf8/-DDEFAULT_COLLATION = utf8_general_ci/-keys = 1/-keys = 1/-keys = 1/-DMYSQL_DATADIR =/data/mysqldb/-keys = 3306/
-DENABLE_DOWNLOADS = 1
Make
Make install
Note: delete the cmakecache.txt file after you refresh the configuration.
################## Explanations and instructions ################### ###########################
-DCMAKE_INSTALL_PREFIX = dir_name
Set the mysql installation directory
-DMYSQL_UNIX_ADDR = file_name
Set the listening socket path, which must be an absolute path name. The default value is/tmp/mysql. sock.
-DDEFAULT_CHARSET = charset_name
Set the character set of the server. By default, MySQL uses the latin1 (CP1252 Western Europe) character set.
The cmake/character_sets.cmake file contains a list of allowed character set names.
-DDEFAULT_COLLATION = collation_name
Set the server's sorting rules.
-DWITH_INNOBASE_STORAGE_ENGINE = 1
-DWITH_ARCHIVE_STORAGE_ENGINE = 1
-DWITH_BLACKHOLE_STORAGE_ENGINE = 1
-DWITH_PERFSCHEMA_STORAGE_ENGINE = 1
Storage engine options:
MyISAM, MERGE, MEMORY, and CSV engines are compiled to the server by default and do not need to be explicitly installed.
Use-DWITH_engine_STORAGE_ENGINE = 1 to statically compile a storage engine to the server.
Available Storage Engine values include ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), and PERFSCHEMA (Performance Schema ).
-DMYSQL_DATADIR = dir_name
Set the mysql database file directory
-DMYSQL_TCP_PORT = port_num
Set the listening port of the mysql server. the default value is 3306.
-DENABLE_DOWNLOADS = bool
Whether to download optional files. For example, if this option is enabled (set to 1), cmake downloads the test suite used by Google to run unit tests.
######################################## ################################
6. modify mysql installation directory and data directory permissions
Cd/usr/local/mysql
Chown-R mysql: mysql.
Cd/data/mysqldb
Chown-R mysql: mysql.
7. initialize the mysql database
Cd/usr/local/mysql
Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysqldb
8. copy the mysql service startup configuration file.
Cp/usr/local/mysql/support-files/my-default.cnf/etc/my. cnf
9. modify the configuration file
Vi/etc/my. cnf
Modify datadir =/data/mysqldb/
10. copy the mysql service startup script and add the PATH
Cp support-files/mysql. server/etc/init. d/mysqld
Vim/etc/profile
PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH
Export PATH
Source/etc/profile
11. start the mysql service and add the service to start automatically
Service mysqld start
Chkconfig -- level 35 mysqld on
12. check whether the mysql service is started.
Netstat-tulnp | grep 3306
Mysql-u root-p
The password is blank. if you can log on to the land, the installation is successful.
13. modify the root password of a MySQL User
Mysqladmin-u root password '123'
6. copy the VM and prepare for mysql master-slave replication.
1. you can clone the VM or directly press ctrl + c ctrl + v to copy the VM.
2. log on to the VM you just copied. because the VM is copied, it needs to be modified in some places.
Hostname mysql42
/Etc/sysconfig/network-scripts/ifcfg-eth0 modify static IP to 192.168.1.42
Rm/etc/udev/rules. d/70-persistent-net.rules delete this file
Reboot restart
3. after restarting the slave server, you can use shell to access the server. you need to modify the auto. cnf File (both copy the VM and cause the fault)
Cd/data/mysqldb/
Vi auto. cnf
Modify one or more numbers in hexadecimal notation for this long string. for example, you can change 0 to 1 and 2 to a. You can change it as needed to ensure that it is different from the 41 server.
7. mysql master/slave configuration
1. set server_id and log-bin.
192.168.1.41 master server
Vi/etc/my. cnf;
Modify server_id = 1;
Modify log-bin = mysqlbin-log;
Service mysqld restart mysql service
192.168.1.42 slave server
Vi/etc/my. cnf;
Modify server_id = 42; (whatever it is, this corresponds to the ip address)
Modify log-bin = mysqlbin-log; (the slave server can be left unspecified)
Service mysqld restart mysql service
2. master server: create an account with master-slave permissions
Go to mysql-uroot-p123456
Grant replication slave on *. * to 'atfire' @ '%' identified by 'atfire123 ';
Atfire is the account, atfire.cn is the password
Flush privileges; refresh the permission to make the permission take effect. This statement must be executed, otherwise it will be invalid.
Show master status; view the current time of the master server bin-log, which is assumed to be mysql-bin.000001 120;
3. set the slave server
Go to mysql-uroot-p123456
(You can enter the help change master to command to view related configurations)
CHANGE MASTER
MASTER_HOST = '1970. 168.1.41 ',
MASTER_USER = 'atfire ',
MASTER_PASSWORD = 'atfire123 ',
MASTER_PORT = 3306,
MASTER_LOG_FILE = 'mysqlbin-log.000001 ',
MASTER_LOG_POS = 120
These parameters are the master server address, user name, password, port number, bin-log file, and current bin-log address (identified in step 2)
4. start slave; enable the slave server thread
5. show slave status/G; view slave server information
If
Slave_IO_Running = yes
Slave_ SQL _Running = yes
It indicates that the operation is successful. at this time, you can add, delete, and modify data on the master server, and the slave server will generate the same data.
If either Slave_IO_Running or Slave_ SQL _Running is yes, an error occurs.
Both no and connecting are incorrect. if both are yes, success is indicated.
According to the author's operations, it is theoretically successful (because I am operating and recording, and succeeded ,)
However, there are many possible failures.
There are many causes of errors. you can search for answers online.
BitsCN.com