How to install mysql5.7 on CentOS7 with yum

来自koorka知识分享
跳转至: 导航搜索

安装独立服务器

  • Adding the MySQL Yum Repository

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

yum localinstall mysql57-community-release-el7-7.noarch.rpm

You can get the newer version from: http://dev.mysql.com/downloads/repo/yum/

  • Install MySQL

yum install mysql-community-server

  • Start MySQL service

systemctl start mysqld

systemctl enable mysqld

  • Get mysql initial root password

grep 'temporary password' /var/log/mysqld.log

Once you know the password you can now run following command to secure your MySQL installation.

mysql_secure_installation

配置Master Slave复制服务器

Replication Master Configuration:

[mysqld]
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
Systemctl restart myself.service

Creating a User for Replication:

CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com';

Obtaining the Replication Master Binary Log Coordinates

FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
Remember the location:
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 73       | test         | manual,mysql     |
+------------------+----------+--------------+------------------+

Create the Data Snapshots of MySQL Server

You can get the data snapshot by two method:

Creating a Data Snapshot Using mysqldump
mysqldump --all-databases --master-data > dbdump.db
Creating a Data Snapshot Using Raw Data Files
mysqladmin shutdown
tar cvf /tmp/db.tar /opt/data/mysql_data
systemctl restart mysqld.service
UNLOCK TABLES;

Setting Up Replication Slaves

Setting the Replication Slave Configuration
vim /etc/my.cnf
[mysqld]
server-id=2
#skip-slave-start=true
read_only=ON
Setting Up Replication with Existing Data
mysql < fulldb.dump
or
tar xvf dbdump.tar
Setting the Master Configuration on the Slave
CHANGE MASTER TO
MASTER_HOST='master_host_name',
MASTER_USER='replication_user_name',
MASTER_PASSWORD='replication_password',
MASTER_LOG_FILE='recorded_log_file_name',
MASTER_LOG_POS=recorded_log_position;
Then start the slave server:
START SLAVE;