DB1 DB2 部署
所需軟件:
mysql-5.0.56.tar.gz
安裝mysql
- cd /root/tools
創建mysql帳號:
- groupadd mysql
- useradd -g mysql -M -s /sbin/nologin mysql
- tar zxvf mysql-5.0.56.tar.gz
- cd mysql-5.0.56
- ./configure \
- --prefix=/usr/local/mysql \
- --enable-assembler \
- --with-extra-charsets=complex \
- --enable-thread-safe-client \
- --with-big-tables \
- --with-readline \
- --with-ssl \
- --with-embedded-server \
- --enable-local-infile \
- --with-plugins=partition,innobase \
- --with-plugin-PLUGIN \
- --with-mysqld-ldflags=-all-static \
- --with-client-ldflags=-all-static
- make && make install
- cd ..
創建數據目錄
建立3306,3307 my.cnf配置文件
- mkdir -p /data/3306/data
- mkdir -p /data/3307/data
- chown -R mysql:mysql /data/3306
- chown -R mysql:mysql /data/3307
- vi /data/3306/my.cnf
- vi /data/3307/my.cnf
my.cnf內容:(3307 my.cnf就是3306 批量替換3307就好)
- #/data/3306/my.cnf
- [client]
- port = 3306
- socket = /data/3306/mysql.sock
- [mysql]
- no-auto-rehash
- [mysqld]
- user = mysql
- port = 3306
- socket = /data/3306/mysql.sock
- basedir = /usr/local/mysql
- datadir = /data/3306/data
- open_files_limit = 1024
- back_log = 600
- max_connections = 800
- max_connect_errors = 3000
- table_cache = 614
- external-locking = FALSE
- max_allowed_packet =8M
- sort_buffer_size = 1M
- join_buffer_size = 1M
- thread_cache_size = 100
- thread_concurrency = 2
- query_cache_size = 2M
- query_cache_limit = 1M
- query_cache_min_res_unit = 2k
- default_table_type = InnoDB
- thread_stack = 192K
- transaction_isolation = READ-COMMITTED
- tmp_table_size = 2M
- max_heap_table_size = 2M
- long_query_time = 1
- log_long_format
- log-bin=mysql3306-bin
- binlog_cache_size = 1M
- max_binlog_cache_size = 1M
- max_binlog_size = 2M
- expire_logs_days = 7
- key_buffer_size = 16M
- read_buffer_size = 1M
- read_rnd_buffer_size = 1M
- bulk_insert_buffer_size = 1M
- myisam_sort_buffer_size = 1M
- myisam_max_sort_file_size = 10G
- myisam_max_extra_sort_file_size = 10G
- myisam_repair_threads = 1
- myisam_recover
- lower_case_table_names = 1
- interactive_timeout = 60
- wait_timeout = 60
- server-id = 1
- innodb_additional_mem_pool_size = 4M
- innodb_buffer_pool_size = 32M
- innodb_data_file_path = ibdata1:128M:autoextend
- innodb_file_io_threads = 4
- innodb_thread_concurrency = 8
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 4M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
- innodb_file_per_table = 0
- [mysqldump]
- quick
- max_allowed_packet = 2M
- [mysqld_safe]
- log-error=/data/3306/mysql_err.log
- pid-file=/data/3306/mysqld.pid
批量替換方法:
- sed -i "s/3306/3307/g" /data/3306/my.cnf >/data/3307/my.cnf
改變my.cnf配置文件的所有權
- chown -R mysql:mysql /data/3306/my.cnf
- chown -R mysql:mysql /data/3307/my.cnf
建立mysql啓動腳本
- vi /data/3306/mysql
- vi /data/3307/mysql
mysql 內容: (3307的mysql需把port改爲3307)
啓動數據庫
- /data/3306/mysql start
- /data/3307/mysql start
添加爲系統自啓動
- echo "/data/3306/mysql start" >>/etc/rc.local
- echo "/data/3307/mysql start" >>/etc/rc.local
用 netstat –ant 命令查看mysql端口,若看到下圖標記的端口,即MYSQL安裝成功!
訪問方法(安裝完初始無密碼):
- mysql -uroot -p -S /data/3306/mysql.sock
- mysql -uroot -p -S /data/3307/mysql.sock
更改root密碼
- /usr/local/mysql/bin/mysqladmin -u root password 'elain' -S /data/3306/mysql.sock
- /usr/local/mysql/bin/mysqladmin -u root password 'elain' -S /data/3307/mysql.sock
登錄MYSQL
- mysql -uroot -p -S /data/3306/mysql.sock
- mysql -uroot -p -S /data/3307/mysql.sock
清理掉系統默認(標記的)的多餘的mysql用戶 3306,3307
- select user,host from mysql.user;
刪除無用帳號
- drop user ''@'db1';
- drop user ''@'localhost';
- drop user 'root'@'db1';
到此,MYSQL 安裝完成,DB1 DB2上安裝完全相同!!
轉載請註明: 轉載自http://www.elain.org
本文鏈接地址:[跟我學中小企業架構部署]之三:數據庫多實例部署