Complete MySQL installation and master-slave dual-machine configuration

Source: Internet
Author: User
Original Author: Marry, contact: macrdy@126.com sample HOST: 192.168.0.1 sample backup machine: 192.168.0.2 ################################# complete MySQL installation ### ########################
Groupadd MySQL
Useradd-G MySQL
MV/root/mysql-5.0.51b.tar.gz/usr/local/src
Tar-zxvf mysql-5.0.51b.tar.gz
CD mysql-5.0.51b
. /Configure -- With-charset = Latin1 -- With-extra-charsets = all -- enable-consumer er -- With-mysqld-ldflags =-all-static -- With-mysqld-user = MySQL -- prefix =/usr/local/mysql-5.0.51b -- localstatedir =/data/mysql5051_db
Make
Make install
Ln-S/usr/local/mysql-5.0.51b/usr/local/MySQL
Mkdir-P/data/mysql5051_db/dbdata
Mkdir-P/data/mysql5051_db/InnoDB
Mkdir-P/data/mysql5051_db/BINLOG
Chown-r MYSQL: MySQL/data/mysql5051_db
Chmod-r 775/data/mysql5051_db
CD/usr/local/src/mysql-5.0.51b
Vim./scripts/ldata =/data/mysql5051_db/dbdata in mysql_install_db
CP./support-files/my-small.cnf/etc/My. CNF
/Usr/local/mysql-5.0.51b/bin/mysql_install_db -- basedir =/usr/local/mysql-5.0.51b -- ldata =/data/mysql5051_db/dbdata -- user = MySQL
Vim/etc/My. CNF
Bind-address = 192.168.0.8
Datadir =/data/mysql5051_db/dbdata/
PID-file =/data/mysql5051_db/My. PID
Log-Slow-queries =/data/mysql5051_db/dbdata/slowquery. SQL
Log-bin =/data/mysql5051_db/BINLOG/sortrepl. Log
################ InnoDB ####################
# Uncomment the following if you are using InnoDB tables
Innodb_data_home_dir =/data/mysql5051_db/InnoDB/
Innodb_data_file_path = ibdata1: 1000 m; ibdata2: 1000 m: autoextend: Max: 800minnodb_log_group_home_dir =/data/mysql5051_db/InnoDB/
Innodb_log_arch_dir =/data/mysql5051_db/InnoDB/
# You can set .. _ buffer_pool_size up to 50-80%
# Of Ram but beware of setting memory usage too high
Innodb_buffer_pool_size = 600 m
Innodb_additional_mem_pool_size = 20 m
# Set .. _ log_file_size to 25% of buffer pool size
Innodb_log_files_in_group = 4
Innodb_log_file_size = 400 m
Innodb_log_buffer_size = 160 m
Innodb_flush_log_at_trx_commit = 0
Innodb_thread_concurrency = 8
# Innodb_flush_method = o_dsync
Innodb_lock_wait_timeout = 50
################ InnoDB ###################### start a service
#/Usr/local/MySQL/bin/mysqld_safe-umysql &
#/Usr/local/mysql-5.0.51b/bin/MySQL
# Close the service
#/Usr/local/MySQL/bin/mysqladmin Shutdown
################################# Complete MySQL installation ### ####################### install the two servers simultaneously according to the preceding steps, and ensure that mysql1. ideally, the latest version of MySQL should be used on the master server and slave server.
2. Set a connection account for the server on the master server.
Mysql> grant replication slave on *. * To 'test' @ '192. 168.0.2 'identified by 'db @ test ';
3. Disable the Master/Slave Database
Linux-A:/data #/usr/local/MySQL/bin/mysqladmin Shutdown
Linux-B:/data #/usr/local/MySQL/bin/mysqladmin Shutdown
Linux-A:/etc # vi my. CNF
Add in [mysqld]
Server-id = 1 # Set the host ID
BINLOG-do-DB = test # sets the database to be synchronized. If there are multiple databases, each database has one row.
Log-bin =/data/mysql5051_db/BINLOG/master. log # MySQL Log
7. modify the configuration file my. CNF of the slave Database
Linux-B:/etc # vi my. CNF
Add in [mysqld]
Server-id = 2 # Set the ID of the slave machine. If multiple slave machines exist, you can add IDS as 3, 4...
Master-host = 192.168.0.1 # host address
Master-user = test # host MySQL Database User
Master-Password = dB @ test # host MySQL Database Password
Replicate-do-DB = test # the database to be synchronized. If multiple databases exist, each database has one row.
Log-bin =/data/mysql5051_db/BINLOG/slave. log # local MySQL Log
Relay-log =/data/mysql5051_db/BINLOG/relay. log # synchronize logs
Log-slave-Updates # synchronization mode
Read-Only
Master-connect-retry = 60
8. Enable Master/Slave Databases
/Usr/local/MySQL/bin/mysqld_safe-umysql & 9. Check synchronization.
Mysql> show slave status \ G
Slave_io_running: Yes
Slave_ SQL _running: Yes
Verify that the synchronization is successful!
10. Import Data
MASTER:
Create Database Test
Here, the slave machine will also have this database, that is to say, MySQL will also synchronize the database creation operations, strong enough.
Then, import the data:
Root @ test:/data #/usr/local/MySQL/bin/MySQL test <./DB. Dump
On the slave machine, check the data, it is OK. When MySQL is started, if -- defaults-extra-file =/usr/local/MySQL/data/my-small.cnf is not specified at./configure
The default value is -- defaults-extra-file =/etc/My. CNF.
File: Mysql-HA.zip
Size: 2 kb
Download: Download

Sample configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.