Ready to work
Execute the following command to install dependencies:
# yum install gcc gcc-c++ ncurses-devel zip make cmake
Execute the following command (make sure there is no mysql legacy information in the system):
rm –rf /etc/my.cnf
userdel mysql
groupdel mysql
Before installing mysql, you need to query the software related to mysql contained in the system.
rpm -qa | grep -i mysql //grep -i is not case sensitive, if mysql is included, the following information will be displayed:
mysql-libs-5.1.71-1.el6.i686 //It is a dependency of several software. Among them, the postfix software in the mini version depends on mysql-libs. Many suggestions on the Internet are to be deleted directly.
# yum remove mysql-libs //Or execute the following command
# rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686 //This is not the best way.
install mysql
1. Upload mysql-5.6.22.tar.gz to /opt/soft:
# rz
2. Enter /opt/soft:
# cd /opt/soft
3. Unzip the installation package:
# tar -zxvf mysql-5.6.22.tar.gz
4. Create the directories required for installation:
# mkdir -p /opt/usr/mysql
# mkdir -p /opt/data/mysql
# mkdir -p /opt/log/mysql
# cd /opt/soft/mysql-5.6.22
# cmake -DCMAKE_INSTALL_PREFIX=/opt/usr/mysql/mysql-5.6.22 \
-DMYSQL_DATADIR=/opt/data/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1
After successful compilation and installation, execute the following command:
# make -j2 && make install -j2
8. Upload the mysql configuration file my.cnf:
9. Initialize the database:
# ./mysql_install_db --basedir=/opt/usr/mysql/mysql-5.6.22 --datadir=/opt/data/mysql --user=root -- defaults-file=/opt/usr/mysql/mysql-5.6.22/etc/my.cnf
# cd /opt/usr/mysql/mysql-5.6.22/support-files
# cp mysql.server ../
Edit line 283 of mysql.server and add the parameter: --user="root"
You can use :set nu to view the line number
Go to the /opt/data/mysql directory and execute the following command:
rm –rf auto.cnf (prevents the same UUID)
auto_increment_increment=2 (the step value is 2 so that two records inserted at the same time will not conflict)
auto_increment_offset=1 (offset is 1)
log_slave_updates=1
auto_increment_increment=2
auto_increment_offset=2 (offset is 2)
log_slave_updates=1
sh mysql.server start
GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl'; (pay attention to the network segment where you are, replace it with % at the end)
GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl';
show master status
Record file and position variables
Generate the following command and execute the following command on the slave library:
change master to
master_host='192.168.56.101', #represents the IP of the main library
master_user='repl',
master_password='repl',
master_log_file='mysql-bin.000004',#file
master_log_pos=334;#position
Execute the name on the slave library
show master status
Record file and position variables
Generate the following commands and execute them on the main library:
change master to
master_host='192.168.56.102', #represents the IP of the main library
master_user='repl',
master_password='repl',
master_log_file='mysql-bin.000004', #file
master_log_pos=120; #position
start slave;
start slave;
show slave status \G;
create database jiajiaozaixian; (if the master is successful, after the master database is created, the slave database will be automatically copied)
grant all privileges on jiajiaozaixian.* to jiajiaozaixian@'%' identified by ' jiajiaozaixian_123';
先检查change master to 命令所指定的ip、用户等信息是否正确;然后确认防火墙已关闭(Service iptables stop);然后检查mysql.enf中增加的配置是否有误。
将mysql.server这个文件copy到/etc/init.d/目录下,改名成mysql
# cp support-files/mysql.server /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql //给mysql这个文件赋予“执行”权限
# chkconfig --add mysql //加入到开机自动运行
# service mysql restart //重新启动MySQL
# chkconfig --list mysql //查看mysql是否开机启动