MySQL master-slave build implementation

Source: Internet
Author: User
Tags install perl openldap

MySQL is a widely used relational database. When the data size expands and the importance increases, the reliability and performance of a single database are severely challenged, so there will be a master-slave database, read/write splitting and other requirements.

First, install mysql on two linux instances, preferably on an intranet machine. You can use an intranet Nic to perform synchronization, and ensure network quality and security.

1. Install common packages:

Yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses- devel curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel openssl-devel openldap-devel nss_ldap openldap-clients openldap-servers

Yum-y install perl-URI perl-DBI perl-String newt-perl

2. Download and install mysql

Wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/

Tar-zxf mysql-5.5.3-m3.tar.gz

3. Compile and install mysql

Cd mysql-5.5.3-m3

. /Configure -- prefix =/usr/local/mysql -- enable-validator -- with-extra-charsets = complex -- enable-thread-safe-client -- with-big-tables --- readline -- with-ssl -- with-embedded-server -- enable-local-infile -- with-plugins = partition, innobase, myisammrg & make install

4. Create mysql users and data folders

/Usr/sbin/groupadd mysql

/Usr/sbin/useradd-g mysql

Chown-R mysql: mysql/usr/local/mysql
Mkdir-p/home/mysql/data

Mkdir-p/home/mysql/binlog
Mkdir-p/home/mysql/relaylog

Chown-R mysql: mysql/home/mysql /*

5. initialize the database

/Usr/local/mysql/bin/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/home/mysql/data -- user = mysql

6. Create a mysql startup and shutdown script: vim/etc/init. d/mysql:

  1. #! /Bin/sh
  2. Mysql_port =3306
  3. Mysql_username ="Root"// Modify it here
  4. Mysql_password ="12345"// Modify it here
  5. Function_start_mysql ()
  6. {
  7. Printf"Starting MySQL... \ n"
  8. /Bin/sh/usr/local/mysql/bin/mysqld_safe -- defaults-file =/home/mysql/my. cnf2> &1>/Dev/null &
  9. }
  10. Function_stop_mysql ()
  11. {
  12. Printf"Stoping MySQL... \ n"
  13. /Usr/local/mysql/bin/mysqladmin-u $ {mysql_username}-p $ {mysql_password}-S/tmp/mysql. sock shutdown
  14. }
  15. Function_restart_mysql ()
  16. {
  17. Printf"Restarting MySQL... \ n"
  18. Function_stop_mysql
  19. Sleep5
  20. Function_start_mysql
  21. }
  22. Function_kill_mysql ()
  23. {
  24. Kill-9$ (Ps-ef | grep'Bin/mysqld_safe'| Grep $ {mysql_port} | awk'{Printf $2 }')
  25. Kill-9$ (Ps-ef | grep'Libexec/mysqld'| Grep $ {mysql_port} | awk'{Printf $2 }')
  26. }
  27. If ["$1"="Start"]; Then
  28. Function_start_mysql
  29. Elif ["$1"="Stop"]; Then
  30. Function_stop_mysql
  31. Elif ["$1"="Restart"]; Then
  32. Function_restart_mysql
  33. Elif ["$1"="Kill"]; Then
  34. Function_kill_mysql
  35. Else
  36. Printf"Usage:/home/mysql {start; stop; restart; kill} \ n"
  37. Fi
  • 1
  • 2
  • 3
  • Next Page

Related Article

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.