Source installation MySQL
Yum Install Ncurses-devel Libaio-devel-ymkdir/server/tools-pcd/server/toolswget https://cmake.org/files/v2.8/ Cmake-2.8.8.tar.gztar XF cmake-2.8.8.tar.gzcd cmake-2.8.8./configuregmake gmake Installwhich cmake/usr/local/bin/ Cmakecd. Useradd-s/sbin/nologin-m mysqlwget Https://downloads.mysql.com/archives/get/file/mysql-5.5.49.tar.gztar XF MYSQL-5.5.49.TAR.GZCD Mysql-5.5.49cmake. -dcmake_install_prefix=/application/mysql-5.5.49-dmysql_datadir=/application/mysql-5.5.49/data-dmysql_unix_ Addr=/application/mysql-5.5.49/tmp/mysql.sock-ddefault_charset=utf8-ddefault_collation=utf8_general_ci-dextra_ Charsets=gbk,gb2312,utf8,ascii-denabled_local_infile=on-dwith_innobase_storage_engine=1-dwith_federated_ Storage_engine=1-dwith_blackhole_storage_engine=1-dwithout_example_storage_engine=1-dwithout_partition_storage _engine=1-dwith_fast_mutexes=1-dwith_zlib=bundled-denabled_local_infile=1-dwith_readline=1-dwith_embedded_ Server=1-dwith_debug=0make make Installln-s/application/mysql-5.5.49//application/mysqlls/application/mysql
Binary package installation MySQL
Useradd-s/sbin/nologin-m mysqlmkdir/application Mkdir/server/tools-pcd/server/toolswget https:// Downloads.mysql.com/archives/get/file/mysql-5.5.49-linux2.6-x86_64.tar.gztar XF mysql-5.5.49-linux2.6-x86_64. TAR.GZMV mysql-5.5.49-linux2.6-x86_64/application/mysql-5.5.49ln-s/application/mysql-5.5.49//application/ Mysqlsed-i ' s#/usr/local/#/application/#g '/application/mysql/bin/mysqld_safecd/application/mysql
To create a multi-instance configuration file and a startup script
Mkdir-p/data/{3306,3307}/datavim/data/3306/my.cnf #3306配置文件 [client]port = 3306socket =/data/ 3306/mysql.sock[mysql]no-auto-rehash[mysqld]user = Mysqlport = 3306socket =/data/3306/mysq L.sockbasedir =/application/mysqldatadir =/data/3306/dataopen_files_limit = 1024back_log = 600max _connections = 800max_connect_errors = 3000table_cache = 614external-locking = Falsemax_allowed_packet = 8Msort_buffer_s ize = 1mjoin_buffer_size = 1mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2Mquery_cache_limit = 1Mquery _cache_min_res_unit = 2k#default_table_type = Innodbthread_stack = 192k#transaction_isolation = READ-COMMITTEDtmp_ Table_size = 2mmax_heap_table_size = 2mlong_query_time = 1pid-file =/data/3306/mysql.pidrelay-log =/data/3306/ Relay-binrelay-log-info-file =/data/3306/relay-log.infobinlog_cache_size = 1mmax_binlog_cache_size = 1Mmax_binlog_ Size = 2mkey_buffer_size = 16mread_buffer_size = 1Mread_rnd_buffer_size = 1mbulk_insert_buffer_size = 1mlower_case_table_names = 1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db = Mysqlserver-id = 1innodb_additional_mem_pool_size = 4minnodb_buffer_pool_size = 32minnodb_data_file_path = Ibdata1:128m:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_ Flush_log_at_trx_commit = 2innodb_log_buffer_size = 2minnodb_log_file_size = 4minnodb_log_files_in_group = 3innodb_max _dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 2M[ MYSQLD_SAFE]LOG-ERROR=/DATA/3306/MYSQL_PETER3306.ERRPID-FILE=/DATA/3306/MYSQLD.PIDVIM/DATA/3307/MY.CNF # 3307 configuration file [client]port = 3307socket =/data/3307/mysql.sock[mysql]no-auto-rehash[mysqld]user = Mysqlport = 3307socket =/data/3307/mysql.sockbasedir =/application/mysqldatadir = /data/3307/dataopen_files_limit = 1024back_log = 600max_connectiONS = 800max_connect_errors = 3000table_cache = 614external-locking = Falsemax_allowed_packet = 8Msort_buffer_size = 1Mjo In_buffer_size = 1mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2mquery_cache_limit = 1Mquery_cache_ Min_res_unit = 2k#default_table_type = Innodbthread_stack = 192k#transaction_isolation = READ-COMMITTEDtmp_table_size = 2mmax_heap_table_size = 2mlong_query_time = 1pid-file =/data/3307/mysql.pidrelay-log =/data/3307/ Relay-binrelay-log-info-file =/data/3307/relay-log.infobinlog_cache_size = 1mmax_binlog_cache_size = 1Mmax_binlog_ Size = 2mkey_buffer_size = 16mread_buffer_size = 1mread_rnd_buffer_size = 1mbulk_insert_buffer_size = 1Mlower_case_table _names = 1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db = Mysqlserver-id = 3innodb_additional_mem_ Pool_size = 4minnodb_buffer_pool_size = 32minnodb_data_file_path = Ibdata1:128m:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_lOg_buffer_size = 2minnodb_log_file_size = 4minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_ Wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 2m[mysqld_safe]log-error=/data/3307/ Mysql_peter3307.errpid-file=/data/3307/mysqld.pidvim/data/3306/mysql #3306启动脚本 #!/bin/bash###################### ############## #this Scripts is created by Peter at 2017-08-31#mail:[email protected]############################ ######## #initport =3306mysql_user= "root" mysql_pwd= "123456" cmdpath= "/application/mysql/bin" mysql_sock= "/data/${ Port}/mysql.sock "#startup Functionfunction_start_mysql () {if [!-e" $mysql _sock "];then printf" starting MyS Ql... \ n "/bin/sh ${cmdpath}/mysqld_safe--defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null & Else printf "MySQL is running...\n" Exit fi} #stop Functionfunction_stop_mysql () {if [!-e "$mysql _so CK "];then printf" MySQL is stopped...\n " Exit else printf "stopping mysql...\n" ${cmdpath}/mysqladmin-u ${mysql_user}-p${mysql_pwd} -s/data/${port}/mysql.sock shutdown fi} #restart Functionfunction_restart_mysql () {printf "Restarting mysql...\n" Function_stop_mysql Sleep 2 function_start_mysql}case $ instart) function_start_mysql;; stop) Function_stop_mysql;; restart) Function_restart_mysql;; *) printf "Usage:/data/${port}/mysql {start|stop|restart}\n" Esacvim/data/3307/mysql #3307启动脚本 #!/bin/bash###### ############################## #this Scripts is created by Peter at 2017-08-31#mail:[email protected]############ ######################## #initport =3307mysql_user= "root" mysql_pwd= "123456" cmdpath= "/application/mysql/bin" MySQL _sock= "/data/${port}/mysql.sock" #startup functionfunction_start_mysql () {if [!-e ' $mysql _sock '];then print F "Starting mysql...\n"/bin/sh ${cmdpath}/mysqld_safe--defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null & Else printf "MySQL is running...\n" Exit fi} #stop Functionfunction_stop_mys QL () {if [!-e "$mysql _sock"];then printf "MySQL is stopped...\n" exit else printf "S Topping mysql...\n "${cmdpath}/mysqladmin-u ${mysql_user}-p${mysql_pwd}-s/data/${port}/mysql.sock shutdown FI} #restart Functionfunction_restart_mysql () {printf "restarting mysql...\n" Function_stop_mysql sleep 2 Function_start_mysql}case $ instart) function_start_mysql;; stop) Function_stop_mysql;; restart) Function_restart_mysql;; *) printf "Usage:/data/${port}/mysql {start|stop|restart}\n" esactree/data/data├──3306│├──data│├──my.cnf│ └──mysql└──3307├──data├──my.cnf└──mysql
Configure file permissions to add MySQL client commands to the path
Chown-r mysql.mysql/datafind/data-type f-name MySQL | Xargs chmod //Startup file has the database administrator password Find/data-type f-name mysql-exec ls-l {} \;-rwx------1 mysql mysql 1203 sep
2 21:12/data/3307/mysql-rwx------1 mysql mysql 1204 Sep 2 21:12/data/3306/mysqlln-s/application/mysql/bin/*/usr /local/sbin
Initialize database, start multi-instance, join boot
/application/mysql/scripts/mysql_install_db--basedir=/application/mysql--datadir=/data/3306/data--user=mysql/ application/mysql/scripts/mysql_install_db--basedir=/application/mysql--datadir=/data/3307/data--user= Mysqlchown-r Mysql.mysql/data/data/3306/mysql Start/data/3307/mysql STARTNETSTAT-NUTLP | grep 330tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27934/mysqld tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 28653/mysqld echo "#mysql Multi Instances" >>/etc/rc.localecho "/data/3306/mysql start" >>/etc /rc.localecho "/data/3307/mysql start" >>/etc/rc.localtail-3/etc/rc.local#mysql Multi instances/data/3306/ MySQL start/data/3307/mysql start
Log in to different instances, set the administrator password
Mysql-s/data/3306/mysql.sockmysql-s/data/3307/mysql.sockmysqladmin-u root-s/data/3306/mysql.sock password ' 123456 ' Mysqladmin-u root-s/data/3307/mysql.sock password ' 123456 ' mysql-uroot-p123456-s/data/3306/mysql.sockmysql-uroot- P123456-s/data/3306/mysql.sock
How do I add one more instance?
#多实例本质是多端口, multiple configuration files. The added process is to change the configuration, start the script, initialize, give permission, start
Single-machine multi-instance master-slave replication
Main Library: Master 3306 from Library: Slave1 3307 from library: Slave2 3308#mastervim/data/3306/my.cnf[mysqld]...server-id = 1log-bin =/data/3306/ Mysql-bin/data/3306/mysql restartmysql-uroot-p123456-s/data/3306/mysql.sockmysql>show variables like ' server_id '; mysql>show variables like ' Log_bin ', mysql>grant replication Slave on * * to ' rep ' @ ' 172.16.1.% ' identified by ' 1234 Mysql>flush Privileges;mysql>select User,host from mysql.user;mysql>show grants for ' rep ' @ ' 172.16.1.% '; Mysql>flush table with read lock; Window cannot be closed, auto unlock mysql>show Master status is turned off, #新开窗口mkdir/server/backup/-pmysqldump-uroot-p123456-s/data/3306/ Mysql.sock--events-a-B | gzip >/server/backup/mysql_bak.$ (Date +%f). sql.gzls-l/server/backupmysql>show Master Status;mysql>unlock tables; #Slave1vim/data/3307/my.cnf[mysqld]...server-id = 3//ID must be unique/data/3307/mysql restartcd/server/backupls- lgzip-d mysql_bak.2017-09-03.sql.gz mysql-uroot-p123456-s/data/3307/mysql.sock < Mysql_bak.2017-09-03.sqlmysQl-uroot-p123456-s/data/3307/mysql.sock << eofchange MASTER tomaster_host= ' 172.16.1.34 ', master_port=3306, Master_user= ' rep ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000001 ', master_log_pos=332; Eofcat/data/3307/data/master.infomysql-uroot-p123456-s/data/3307/mysql.sock-e "start slave;" Mysql-uroot-p123456-s/data/3307/mysql.sock-e "show slave status\g;" | Egrep "Io_running| Sql_running|_behind_master "#Mastermysql-uroot-p123456-s/data/3306/mysql.sock-e" CREATE database Peter; " #Slave1mysql-uroot-p123456-s/data/3307/mysql.sock-e "show databases like ' Peter ';
MySQL-5.5.49 installation, multi-instance, master-slave replication