Chapter 0 of MySql, installation and cluster configuration
1, MySql installation
1. RPM installation
RPM installation, unable to customize some installation paths and configuration file paths
##Fill in the pit later
2. Generic installation
Binary precompiled Generic, download address:
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@mysq|1 ~ ]# groupadd mysql [root@mysql1 ~ ]# useradd -r -g mysql -s /bin/false mysql [root@mysql1 ~ ]# cd /usr/local [root@mysq|1 local]# tar -zxvf /opt/software/file/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz [root@mysq|1 local]# ln -s mysql-5.7.29-linux-glibc2.12-x86_64 mysql #Hyperlinks 1,mysql initialization //No compilation and installation process [root@mysq|1 local]# cd mysql [root@mysql1 mysq|]# mkdir mysql-files [root@mysql1 mysq|]# chmod 750 mysql-files [ root@mysql1 mysql ]# chown -R mysql . [root@mysql1 mysql]# chgrp -R mysql . [root@mysql1 mysq|]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ##Initialize the directory. Note that a mysql password will be generated here. Remember [root@mysq|1 mysq|]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data ##Public key and private key [root@mysql1 mysq|]# chown -R root . [root@mysql1 mysq|]# chown -R mysql data mysql-files 2,create profile [root@mysql1 mysq|]# cp -rf support-files/my-default.cnf /etc/my.cnf ##Without my-default.cnf For files, create them directly under / etc my.cnf file ##Fill in the following: ##[mysqld] ##basedir=/usr/local/mysql ##datadir=/usr/local/mysql/data 3,take mysql Order deposit path [root@mysq|2 mysq|]# /usr/local/mysql/bin/mysql ##Orders don't work [root@mysql1 mysq|]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile [root@mysq|1 mysq|]# source /etc/profile ##echo $PATH to see if it's added 4,start-up mysql //Method 1: use mysqld_safe [root@mysql1 mysq|]# bin/mysqld_safe --user=mysql & //Method 2: use mysql.service Script start [use this generally] [root@mysq|1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@mysq|1 mysq|]# chmod a+x /etc/init.d/mysqld [root@mysq|1 mysq|]# chkconfig --add mysqld [root@mysq|l1 mysq|]# chkconfig mysqld on ##Set startup [root@mysq|1 mysq|]# service mysqld start ##mysql start ##service mysqld start ##mysql start ##service mysqld stop ##Close mysql ##service mysqld restart ##Restart mysql ##service mysqld status ##View mysql status 5,Initialize password change [root@mysql1 mysq|]# mysql -uroot -p ##Password is empty ##If you don't log in ##vi /etc/mysql.cnf ##add to ##skip-grant-tables ##Restart mysql [root@mysql1 mysq|]# use mysql [root@mysql1 mysq|]# UPDATE user SET authentication_string=PASSWORD('admin123') where USER='root'; ##Change Password //perhaps alter user root@'localhost' identified by 'admin123'; [root@mysql1 mysq|]# FLUSH PRIVILEGES; ##Refresh permissions 6,Remote access [root@mysql1 mysq|]# Restart mysql and log in with the new password [root@mysql1 mysq|]# grant all privileges on *.* to 'root'@'% 'identified by 'admin123' with grant option; ##Remote access to mysql [root@mysql1 mysq|]# FLUSH PRIVILEGES; ##Refresh permissions 7,Reinitialize if necessary mysql [root@mysql1 ~]# killall mysqld [root@mysql1 ~]# rm -rf /usr/local/mysql/data [root@mysql1 mysql]# chown -R mysq| . [root@mysql1 mysql]# chgrp -R mysql . [root@mysql1 mysq|]# bin/mysqld -initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data [root@mysql1 mysq|]# bin/mysql_ssl_rsa_setup [ root@mysql1 mysql ]# chown -R root . [root@mysql1 mysql ]# chown -R mysql data mysql-files
Problems encountered:
1, bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory //resolvent: yum install -y libaio //After installation, initialization is OK //perhaps yum install -y libaio.so.1 2,killall no such file or directory ##Without an order yum -y install killall //or yum providers killall See where there is killall And then yum install package
3. Source Code installation
Source Code installation
##Fill in the pit later
2, Mysql master-slave replication
Principle:
The MySQL replication process is divided into three steps: 1 master logs changes to the binary log. These logging processes are called binary log events 2 slave copies the binary log events of the master to its relay log 3. Slave redoes the events in the relay log and applies the changes to its own database. MySQL replication is asynchronous and serial
1. Single master single slave
1.1 master settings
Modify add / etc/my.cnf
[mysqld] ##Primary server unique ID [required] server-id=1 ##Enable binary log ##chown mysql.mysql /Usr / local / MySQL grant permission log-bin=mysql-bin ##root directory basedir=/usr/local/mysql ##Temporary directory tmpdir=/usr/local/mysql ##Data catalog datadir=/usr/local/mysql/data ##The host can read and write: 0 read-only=0 ##mysql is the factory default database for setting the database that does not need to be copied binlog-ignore-db=mysql ##Set up the database to be replicated binlog-do-db=Name of the primary database to be copied
master establishes an account and authorizes the copy permission to slave
##Syntax: GRANT REPLICATION SLAVE ON *.* TO 'account' @ 'slave IP' IDENTIFIED BY 'admin123'; ##to grant authorization GRANT REPLICATION SLAVE ON *.* TO 'ren'@'192.168.0.107' IDENTIFIED BY 'admin123'; ##Refresh permissions flush privileges; ##View the host status file where to start copying the binary file position show master status;
1.2. slave setting
Modify / etc/my.cnf
[mysqld] ##Primary server unique ID [required] server-id=2 ##Enable binary log ##chown mysql.mysql /Usr / local / MySQL authorization log-bin=mysql-bin ##root directory basedir=/usr/local/mysql ##Temporary directory tmpdir=/usr/local/mysql ##Data catalog datadir=/usr/local/mysql/data
slave configure the host to be copied from
##grammar ## CHANGE MASTER TO MASTER_HOST = 'host IP', MASTER_USER='ren',MASTER_PASSWORD='admin123', ## MASTER_ LOG_ File ='name of file ', MASTER_LOG_POS=position number; ##to configure CHANGE MASTER TO MASTER_HOST='192.168.0.111', MASTER_USER='ren',MASTER_PASSWORD='admin123', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=341; ##Start replication from server start slave; ##Check - if the following two parameters are YES, the master-slave configuration is successful show slave statusG ##Slave_IO_Running : YES ##Slave_SQL_Running: YES ##############Stop master-slave replication################# stop slave