mysql linux free installation configuration
1. The original installation must be deleted before installation
You need to check whether the following files exist , and delete them if they are stored
/etc/my.cnf
/etc/init.d/mysqld
2. mysql- dependent libraries
shell> yum search libaio # search for info shell> yum install libaio # install library
3. Create mysql and user groups, -s /bin/false means that the user cannot log in
shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql
4. Unzip the installation package to the specified directory
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql
5. Add permissions for the mysql user
shell> chown -R mysql ./ shell> chgrp -R mysql ./ #Create data directory and add permissions shell> mkdir -p /data/mysql shell> chown -R mysql:mysql /data/mysql
6. Copy the configuration file
shell> cp support-files/my-default.cnf /etc/my.cnf #Change setting shell> vim /etc/my.cnf shell> cp support-files/mysql.server /etc/init.d/mysql
7. Initialize the mysql library
shell> ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
8. Add environment variables
shell> vi /etc/profile PATH=/home/cbt/svr/mysql/bin:$PATH export PATH #Make the changes just now take effect shell> source /etc/profile
9. Startup and other configurations #Start the database
service mysql start
(If the startup fails, check the hosts file to configure the IP address)
#boot start
chkconfig mysqld on
#initialize some settings of mysql
mysql_secure_installation #enter Enter current password for root (enter for none): #y, set the root password of mysql Set root password?[Y/n] y #The following are all yes Remove anonymous users?[Y/n] y Disallow root login remotely?[Y/n] y Remove test database and access to it?[Y/n] y Reload privilege tables now?[Y/n] y ThanksforusingMySQL!
10. Allow remote login
1. mysql> use mysql; 2. mysql> select host,user,password from user; 3. mysql> update user set password=password('123456') where user='root'; 4. mysql> update user set host='%' where user='root' and host='localhost'; 5. mysql> flush privileges;
++++++++++++++++++++++++++++++++++++++++++++++++++
The basic idea of configuring master-slave synchronization is as follows:
1.master my.cnf configuration
#Database ID number, when it is 1, it means Master, where master_id must be a positive integer value between 1 and 232-1; server-id = 1 #binlog format binlog-format=ROW #Enable binary logging; log-bin=mysql-master-bin #Whether it is recorded in the log when the slave is updated; log-slave-updates=true #Open semi-synchronization rpl_semi_sync_master_enabled=ON #The name of the binary database that needs to be synchronized; binlog-do-db=tuling (here you need to synchronize the database) #The name of the unsynchronized binary database, if it is not set, it can be commented out; binlog-ignore-db=information_schema binlog-ignore-db=mysql binlog-ignore-db=personalsite binlog-ignore-db=test #Set the generated log file name; log-bin="D:/Database/materlog" #Write the updated record to the binary file; log-slave-updates
(If mysql cannot be started after restarting, it is found that there is a problem with rpl_semi_sync_master_enabled=ON by looking for the err file, comment it out )
Configure semi-sync by following steps
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so'; Query OK, 0 rows affected (0.21 sec) mysql> show variables like 'rpl_%'; +------------------------------------+-------+ | Variable_name | Value | +------------------------------------+-------+ | rpl_recovery_rank | 0 | | rpl_semi_sync_master_enabled | OFF | | rpl_semi_sync_master_timeout | 10000 | | rpl_semi_sync_master_trace_level | 32 | | rpl_semi_sync_master_wait_no_slave | ON | +------------------------------------+-------+ 5 rows in set (0.00 sec) Set variable to enable semi-synchronous replication mysql> set global rpl_semi_sync_master_enabled=on ; Query OK, 0 rows affected (0.02 sec) mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so'; Query OK, 0 rows affected (0.21 sec) mysql> show variables like 'rpl_%'; +------------------------------------+-------+ | Variable_name | Value | +------------------------------------+-------+ | rpl_recovery_rank | 0 | | rpl_semi_sync_master_enabled | OFF | | rpl_semi_sync_master_timeout | 10000 | | rpl_semi_sync_master_trace_level | 32 | | rpl_semi_sync_master_wait_no_slave | ON | +------------------------------------+-------+ 5 rows in set (0.00 sec) Set variable to enable semi-synchronous replication mysql> set global rpl_semi_sync_master_enabled=on ; Query OK, 0 rows affected (0.02 sec)
2. Create a user database for master-slave synchronization (it is a user used to connect with the slave database, not related to the login account of the master database)
grant replication slave,super,reload on *.* to slave1@192.168.142.128 identified by '123456';
3. View the master node status
mysql> show master status #View the connected slave host on the main library mysql> show slave hosts; #View all binlog logs mysql> show binary logs; #View all binlog events mysql> show binlog events in 'mysql-bin.000003';
4.slave my.cnf configuration
#If the Slave library needs to be added, this id will be postponed; server-id = 2 log-bin=mysql-bin #Main library host master-host = 192.168.168.253 #The user established in the master database server for the backup of the slave server master-user = enslave master-password = ****** master-port = 3306 #If the main server is found to be disconnected, the time difference for reconnection; master-connect-retry=60 #Databases that do not need to be backed up; replicate-ignore-db=mysql #Database to be backed up replicate-do-db=minishop log-slave-update
5.Slave related operations
#start slave mysql>start slave; mysql>stop slave; #View slave status show slave status\G;
Remarks: 1) Run the configured master database server before the slave database server, so when running the slave database server, the File and Position of the master library and the settings of Master_Log_File and Read_Master_Log_Pos on the slave library will be consistent. Otherwise, inconsistencies may occur. This can also be adjusted by command.
2) If you find that the master-slave replication fails, you can first shut down the slave database server, then delete the relay-log.info, hosname-relay-bin*, master.info and other files in the data directory of the slave database server, and restart the slave server.
The slave node modifies the master configuration
mysql>change master to master_host='192.168.142.128', master_user='slave1', master_password='123456' ,MASTER_AUTO_POSITION = 341;
Separation of read and write to achieve 360 Atlas
Install and uninstall Atlas
#install _
shell> rpm -i Atlas-2.2.1.el6.x86_64.rpm
#uninstall _
shell> rpm -e Atlas-2.2.1.el6.x86_64.rpm
The installation directory is in /usr/local/mysql-proxy/
Atlass configuration
#The IP and port of the MySQL main library connected to the Atlas backend , multiple items can be set, separated by commas
proxy-backend-addresses = 127.0.0.1:3306
#The IP and port of the MySQL slave library connected to the Atlas backend. The number after @ represents the weight, which is used for load balancing. If omitted, the default value is 1. Multiple items can be set, separated by commas.
#proxy-read-only-backend-addresses = 127.0.0.1:3305@1
#Username and its corresponding encrypted MySQL password. The password is encrypted using the encryption program encrypt in the PREFIX/bin directory . User password All master and slave libraries must be one to one
pwds = root:/iZxz+0GRoA=
#Atlas listens on the working interface IP and port
proxy-address = 0.0.0.0:1234
Start and shut down Atlas
./mysql-proxyd test start
./mysql-proxyd test stop
Admin login as proxy
mysql -h127.0.0.1 -P2345 -uroot -proot