標籤:mysql
1.編譯安裝cmake
# tar zxf cmake-3.5.2.tar.gz# ./configure# gmake # gmake install
3.編譯安裝MySQl
#useradd mysql -s /sbin/nologin -M # yum install ncurses-devel -y# yum install libaio-devel -y# tar xvf mysql-5.5.49.tar.gz# cd mysql-5.5.49
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.49 -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=0
# make# make install# ln -s /usr/local/mysql-5.5.49 /usr/local/mysql# echo ‘export PATH=/usr/local/mysql/bin/:$PATH‘ >>/etc/profile# tail -l /etc/profile# source /etc/profile# echo $PATH
4.建立多執行個體資料目錄
//以兩個執行個體為例
# mkdir -p /data/{3306,3307}/data# tree /data//data/|-- 3306| `-- data`-- 3307 `-- data
5.設定第一個執行個體設定檔
# vi /data/3306/my.cnf[client]port = 3306socket = /data/3306/mysql.sock[mysql]no-auto-rehash[mysqld]user = mysqlport = 3306socket = /data/3306/mysql.sockbasedir = /usr/local/mysqldatadir = /data/3306/dataopen_files_limit = 1024back_log = 600max_connections = 800max_connect_errors = 3000table_cache = 614external-locking = FALSEmax_allowed_packet =8Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2Mquery_cache_limit = 1Mquery_cache_min_res_unit = 2kthread_stack = 192Ktmp_table_size = 2Mmax_heap_table_size = 2Mlong_query_time = 1pid-file = /data/3306/mysql.pidlog-bin = /data/3306/mysql-binrelay-log = /data/3306/relay-binrelay-log-info-file = /data/3306/relay-log.infobinlog_cache_size = 1Mmax_binlog_cache_size = 1Mmax_binlog_size = 2Mexpire_logs_days = 7key_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_3306.errpid-file=/data/3306/mysqld.pid
6.設定啟動文本
vi /data/3306/mysqld#!/bin/shport=3306mysql_user="root"mysql_pwd=""CmdPath="/application/usr/local/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup functionfunction_start_mysql(){ if [ ! -e "$mysql_sock" ];then printf "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_mysql(){ if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping 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 $1 instart) function_start_mysql;;stop) function_stop_mysql;;restart) function_restart_mysql;;*) printf "Usage: /data/${port}/mysql {start|stop|restart}\n"esac# chown -R mysql.mysql /data/# chmod +x mysqld
7.初始化資料庫
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/3306/data/ --user=mysql
8.啟動資料庫
# /data/3306/mysqld start
9.登入資料庫
# mysql -S /data/3306/mysql.sock
10.配置第二個執行個體
# cp /data/3306/my.cnf /data/3307/my.cnf# cp /data/3306/mysqld /data/3307/mysqld//server-id 改為2server-id = 2# sed -i ‘s#3306#3307#g‘ /data/3307/my.cnf# sed -i ‘s#3306#3307#g‘ /data/3307/mysqld# chown -R mysql.mysql /data/# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/3307/data/ --user=mysql# /data/3307/mysqld start# mysql -S /data/3307/mysql.sock
部署mysql多執行個體