I. Preparations before installation
Download Mysql source package: Recommended official site http://www.mysql.com/
Configure the Ubuntu Environment
Add a mysql user group and user:
Groupadd mysql
Useradd-g mysql
Create the directory required for Installation
Master instance installation directory:
Mkdir/opt/mastermysql/
Mkdir/opt/mastermysql/data/
Slave instance installation directory:
Mkdir/opt/slavemysql/
Mkdir/opt/slavemysql/data
Change permissions:
Chown mysql: mysql-R/opt/mastermysql/data
Chown mysql: mysql-R/opt/slavemysql/data
Ii. Install the master instance
Copy the source package to the main directory/root
Decompress:
Cd/root
Mkdir mastermysql
Tar-xv-f mysql-5.5.18.tar.gz-C ~ /Mastermysql
Go to the source code directory:
Cd mastermysql/mysql-5.5.18
Compilation Configuration:
Cmake-DCMAKE_INSTALL_PREFIX =/opt/mastermysql
-DSYSCONFDIR =/opt/mastermysql/etc
-DMYSQL_DATADIR =/opt/mastermysql/data-DMYSQL_TCP_PORT = 3307
-DMYSQL_UNIX_ADDR =/tmp/mysqld. sock-DMYSQL_USER = mysql
-DEXTRA_CHARSETS = all
-DWITH_READLINE = 1-DWITH_SSL = system
-DWITH_EMBEDDED_SERVER = 1-DENABLED_LOCAL_INFILE = 1
-DWITH_INNOBASE_STORAGE_ENGINE = 1
-DWITHOUT_PARTITION_STORAGE_ENGINE = 1
Make
Make install
Installation Complete, configuration and database Initialization
Make/opt/mastermysql/etc
Cp support-files/my-medium.cnf/opt/mastermysql/etc/my. cnf
Initialize Database
Chmod 755 scripts/mysql_install_db
Scripts/mysql_install_db -- user = mysql -- basedir =/opt/mastermysql
-- Datadir =/opt/mastermysql/data
Create shell scripts for mysql Database Management
Mkdir/opt/mysql/init. d
Cp support-files/mysql. server/opt/mastermysql/init. d/mysql
Grant the shell script executable permission:
Chmod + x/opt/mastermysql/init. d/mysql
3. Install the slave instance
Replace all master characters in step 2 with slave, and replace the DMYSQL_TCP_PORT parameter in configure with 3308.
4. Configure master-slave
Start the master-slave instance:
/Opt/mastermysql/init. d/mysql start
/Opt/slavemysql/init. d/mysql start
Configure master
Vi/opt/mastermysql/etc/my. cnf
Add: server-id = 1
Log-bin = mysql-bin
Log on to the master instance
/Opt/mastermysql/bin/mysql-uroot
Create a duplicate account
Grant replication on *. * repl @ localhost identified by '20140901'
Show master status \ G;
Record File, Position value will be used later
Log on to the slave instance
/Opt/slavemysql/bin/mysql-uroot
Configure master-slave
Change master to master_host = '192. 0.0.1 ', master_port = 127, master_user = 'repl ',
Master_password = '123', master_log_file = 'content of the above file ',
Master_log_pos = 'content of the above Position ';
Start slave;
5. Test
Because both databases are installed with the same source code, their database content is the same
No synchronization is required. Create a table on the master, insert data, and check whether the table and data exist on the slave.
Vi. Summary
The above steps are recorded and written after my configuration is successful. You are welcome to criticize and correct them. As long
Master-slave replication is easy to understand the source code installation process.