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:
- #! /Bin/sh
- Mysql_port =3306
- Mysql_username ="Root"// Modify it here
- Mysql_password ="12345"// Modify it here
- Function_start_mysql ()
- {
- Printf"Starting MySQL... \ n"
- /Bin/sh/usr/local/mysql/bin/mysqld_safe -- defaults-file =/home/mysql/my. cnf2> &1>/Dev/null &
- }
- Function_stop_mysql ()
- {
- Printf"Stoping MySQL... \ n"
- /Usr/local/mysql/bin/mysqladmin-u $ {mysql_username}-p $ {mysql_password}-S/tmp/mysql. sock shutdown
- }
- Function_restart_mysql ()
- {
- Printf"Restarting MySQL... \ n"
- Function_stop_mysql
- Sleep5
- Function_start_mysql
- }
- Function_kill_mysql ()
- {
- Kill-9$ (Ps-ef | grep'Bin/mysqld_safe'| Grep $ {mysql_port} | awk'{Printf $2 }')
- Kill-9$ (Ps-ef | grep'Libexec/mysqld'| Grep $ {mysql_port} | awk'{Printf $2 }')
- }
- If ["$1"="Start"]; Then
- Function_start_mysql
- Elif ["$1"="Stop"]; Then
- Function_stop_mysql
- Elif ["$1"="Restart"]; Then
- Function_restart_mysql
- Elif ["$1"="Kill"]; Then
- Function_kill_mysql
- Else
- Printf"Usage:/home/mysql {start; stop; restart; kill} \ n"
- Fi