1.爲何數據目錄和日誌目錄須要分開?html
2.如何標準化配置多實例?(例如:一臺物理主機上部署3306與3307兩個實例)mysql
3.詳細描述MySQL編譯安裝的過程(截圖安裝步驟)linux
不一樣做用的文件放到不一樣的磁盤、目錄之上c++
數據文件sql
日誌文件數據庫
使用多個不一樣配置文件
優勢:配置簡單
缺點:不方便管理安全
經過官方mysqld_mutil使用單獨的配置文件
優勢:方便集中管理
缺點:多個實例配置均在一個文件,不太方便bash
問題:服務器
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm yum install -y mysql57-community-release-el7-11.noarch.rpm https://dev.mysql.com/doc/refman/5.5/en/source-installation.html yum install -y cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl openssl-devel ncurses
service iptables stauts service iptables stop chkconfig iptables off
firewall-cmd --state systemctl list-unit-files|grep firewalld.service systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service 或者 firewall-cmd --set-default-zone=trusted
getenforce setenforce 0 vi /etc/selinux/config permissive
rpm -qa|grep -i mysql
groupadd mysql useradd mysql -g mysql -s /bin/false
mkdir -p /data/my3306/{data,log/binlog,log/iblog,run,tmp} chown -R mysql:mysql /data vi ~/.bash_profile PATH=$PATH:$HOME/bin:/data/my3306/bin export PATH
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.39-1.el7.src.rpm rpm2cpio MySQL-5.6.39-1.el7.src.rpm | cpio -div tar -zxvf mysql-5.6.39.tar.gz
cmake \ -DCMAKE_INSTALL_PREFIX=/data/my3306 \ -DINSTALL_DATADIR=/data/my3306/data \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_SSL=yes \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/data/my3306/run/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DSYSCONFDIR=/etc \ -DWITH_READLINE=on
結果網絡
CMake Warning: Manually-specified variables were not used by the project: INSTALL_DATADIR WITH_READLINE -- Build files have been written to: /dvd/mysql-5.6.39
若是cmake失敗,刪除目錄下的CMakeCache.txt文件
而後是make
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o Linking CXX executable my_safe_process [100%] Built target my_safe_process
最後是make install
-- Up-to-date: /data/my3306/sql-bench/test-transactions -- Up-to-date: /data/my3306/sql-bench/test-wisconsin -- Installing: /data/my3306/sql-bench/cmake_install.cmake -- Installing: /data/my3306/sql-bench/CTestTestfile.cmake
參數含義
-DCMAKE_INSTALL_PREFIX= 指向mysql安裝目錄 -DINSTALL_SBINDIR=sbin 指向可執行文件目錄(prefix/sbin) -DMYSQL_DATADIR=/var/lib/mysql 指向mysql數據文件目錄(/var/lib/mysql) -DSYSCONFDIR=/etc/mysql 指向mysql配置文件目錄(/etc/mysql) -DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目錄(prefix/lib/mysql/plugin) -DINSTALL_MANDIR=share/man 指向man文檔目錄(prefix/share/man) -DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安裝目錄(prefix/share) -DINSTALL_LIBDIR=lib/mysql 指向對象代碼庫目錄(prefix/lib/mysql) -DINSTALL_INCLUDEDIR=include/mysql 指向頭文件目錄(prefix/include/mysql) -DINSTALL_INFODIR=share/info 指向info文檔存放目錄(prefix/share/info) prefix官方推薦設爲/usr Storage Engine相關 類型csv,myisam,myisammrg,heap,innobase,archive,blackhole 若想啓用某個引擎的支持:-DWITH_<ENGINE>_STORAGE_ENGINE=1 如: -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 若想禁用某個引擎的支持:-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1 如: -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 Library相關 -DWITH_READLINE=1 啓用readline庫支持(提供可編輯的命令行) -DWITH_SSL=system 啓用ssl庫支持(安全套接層) -DWITH_ZLIB=system 啓用libz庫支持(zib、gzib相關) -DWTIH_LIBWRAP=0 禁用libwrap庫(實現了通用TCP包裝的功能,爲網絡服務守護進程使用) -DMYSQL_TCP_PORT=3306 指定TCP端口爲3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 指定mysql.sock路徑 -DENABLED_LOCAL_INFILE=1 啓用本地數據導入支持 -DEXTRA_CHARSETS=all 啓用額外的字符集類型(默認爲all) -DDEFAULT_CHARSET=utf8 指定默認的字符集爲utf8 -DDEFAULT_COLLATION=utf8_general_ci 設定默認排序規則(utf8_general_ci快速/utf8_unicode_ci準確) -DWITH_EMBEDDED_SERVER=1 編譯嵌入式服務器支持 -DMYSQL_USER=mysql 指定mysql用戶(默認爲mysql) -DWITH_DEBUG=0 禁用debug(默認爲禁用) -DENABLE_PROFILING=0 禁用Profiling分析(默認爲開啓) -DWITH_COMMENT='string' 一個關於編譯環境的描述性註釋
chown -R mysql:mysql /data cd /data/my3306 ./scripts/mysql_install_db --defaults-file=/data/my3306/my.cnf --datadir=/data/my3306/data --user=mysql
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db: Data::Dumper
報錯了,須要安裝Perl
yum install -y perl perl-devel perl-Data-Dumper
須要在bin目錄下執行,否則會報錯:FATAL ERROR: Could not find ./bin/my_print_defaults
cd /data/my3306/bin ./mysqld_safe --defaults-file=/data/my3306/my.cnf --user=mysql &
[root@mysql01 bin]# 180206 23:25:09 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
[root@mysql01 bin]# netstat -ano|grep 3306 tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0) unix 2 [ ACC ] STREAM LISTENING 57177 /data/my3306/run/mysql.sock [root@mysql01 bin]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.39-log Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.12 sec)
mkdir -p /data/my3307/{data,log/binlog,log/iblog,run,tmp} chown -R mysql:mysql /data/my3307
2.修改my.cnf
cp -rp /data/my3306/my.cnf /data/my3307/my.cnf sed -i {s/3306/3307/g} /data/my3307/my.cnf
basedir=/data/my3306 參數不變
cd /data/my3306/ ./scripts/mysql_install_db --defaults-file=/data/my3307/my.cnf --datadir=/data/my3307/data --user=mysql
cd /data/my3306/bin ./mysqld_safe --defaults-file=/data/my3307/my.cnf --user=mysql &
[root@mysql01 bin]# netstat -lnptu|grep 330 tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0) tcp6 0 0 :::3307 :::* LISTEN off (0.00/0/0)
[root@mysql01 bin]# mysql -P3307 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.39-log Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.23 sec)
mkdir -p /data/my3308/{data,log/binlog,log/iblog,run,tmp} chown -R mysql:mysql /data/my3308
2. 修改my.cnf 增長
basedir=/data/my3306 參數不變
cd /data/my3306 ./scripts/mysql_install_db --defaults-file=/data/my3306/my.cnf --datadir=/data/my3308/data --user=mysql
cd /data/my3306/bin mysqld_multi --defaults-extra-file=/data/my3306/my.cnf start 1,2
180207 00:19:24 mysqld_safe Logging to '/data/my3306/log/error.log'. 180207 00:19:24 mysqld_safe The file /mysqld
啓動信息以下:
mysqld_multi log file version 2.16; run: Wed Feb 7 10:43:34 2018 Starting MySQL servers 180207 10:43:35 mysqld_safe Logging to '/data/my3306/log/error.log'. 180207 10:43:35 mysqld_safe Logging to '/data/my3308/log/error.log'. 180207 10:43:35 mysqld_safe Starting mysqld daemon with databases from /data/my3306/data 180207 10:43:35 mysqld_safe Starting mysqld daemon with databases from /data/my3308/data
[root@mysql01 bin]# netstat -lnptu|grep 330 tcp6 0 0 :::3306 :::* LISTEN 25185/mysqld tcp6 0 0 :::3307 :::* LISTEN 26218/mysqld tcp6 0 0 :::3308 :::* LISTEN 25197/mysqld
$print_defaults = "$opt->{builddir}/extra/my_print_defaults";
$print_defaults = find_in_basedir($opt,"file","my_print_defaults","bin","extra");
$print_defaults='./bin/my_print_defaults';
3306和3308的配置以下:
[client] port=3306 socket=/data/my3306/mysql.sock [mysqld_multi] mysqld=/data/my3306/bin/mysqld_safe mysqladmin=/data/my3306/bin/mysqladmin log=/data/my3306/log/mysqld_multi.log [mysql] pid_file=/data/my3306/run/mysqld.pid [mysqld1] autocommit=1 general_log=off explicit_defaults_for_timestamp=true # system basedir=/data/my3306 datadir=/data/my3306/data max_allowed_packet=1g max_connections=3000 max_user_connections=2800 open_files_limit=65535 pid_file=/data/my3306/run/mysqld.pid port=3306 server_id=101 skip_name_resolve=ON socket=/data/my3306/run/mysql.sock tmpdir=/data/my3306/tmp #binlog log_bin=/data/my3306/log/binlog/binlog binlog_cache_size=32768 binlog_format=row expire_logs_days=7 log_slave_updates=ON max_binlog_cache_size=2147483648 max_binlog_size=524288000 sync_binlog=100 #logging log_error=/data/my3306/log/error.log slow_query_log_file=/data/my3306/log/slow.log log_queries_not_using_indexes=0 slow_query_log=1 log_slave_updates=ON log_slow_admin_statements=1 long_query_time=1 #relay relay_log=/data/my3306/log/relaylog relay_log_index=/data/my3306/log/relay.index relay_log_info_file=/data/my3306/log/relay-log.info #slave slave_load_tmpdir=/data/my3306/tmp slave_skip_errors=OFF #innodb innodb_data_home_dir=/data/my3306/log/iblog innodb_log_group_home_dir=/data/my3306/log/iblog innodb_adaptive_flushing=ON innodb_adaptive_hash_index=ON innodb_autoinc_lock_mode=1 innodb_buffer_pool_instances=8 #default innodb_change_buffering=inserts innodb_checksums=ON innodb_buffer_pool_size= 128M innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend innodb_doublewrite=ON innodb_file_format=Barracuda innodb_file_per_table=ON innodb_flush_log_at_trx_commit=1 innodb_flush_method=O_DIRECT innodb_io_capacity=1000 innodb_lock_wait_timeout=10 innodb_log_buffer_size=67108864 innodb_log_file_size=1048576000 innodb_log_files_in_group=4 innodb_max_dirty_pages_pct=60 innodb_open_files=60000 innodb_purge_threads=1 innodb_read_io_threads=4 innodb_stats_on_metadata=OFF innodb_support_xa=ON innodb_use_native_aio=OFF innodb_write_io_threads=10 [mysqld2] autocommit=1 general_log=off explicit_defaults_for_timestamp=true # system basedir=/data/my3306 datadir=/data/my3308/data max_allowed_packet=1g max_connections=3000 max_user_connections=2800 open_files_limit=65535 pid_file=/data/my3308/run/mysqld.pid port=3308 server_id=101 skip_name_resolve=ON socket=/data/my3308/run/mysql.sock tmpdir=/data/my3308/tmp #binlog log_bin=/data/my3308/log/binlog/binlog binlog_cache_size=32768 binlog_format=row expire_logs_days=7 log_slave_updates=ON max_binlog_cache_size=2147483648 max_binlog_size=524288000 sync_binlog=100 #logging log_error=/data/my3308/log/error.log slow_query_log_file=/data/my3308/log/slow.log log_queries_not_using_indexes=0 slow_query_log=1 log_slave_updates=ON log_slow_admin_statements=1 long_query_time=1 #relay relay_log=/data/my3308/log/relaylog relay_log_index=/data/my3308/log/relay.index relay_log_info_file=/data/my3308/log/relay-log.info #slave slave_load_tmpdir=/data/my3308/tmp slave_skip_errors=OFF #innodb innodb_data_home_dir=/data/my3308/log/iblog innodb_log_group_home_dir=/data/my3308/log/iblog innodb_adaptive_flushing=ON innodb_adaptive_hash_index=ON innodb_autoinc_lock_mode=1 innodb_buffer_pool_instances=8 #default innodb_change_buffering=inserts innodb_checksums=ON innodb_buffer_pool_size= 128M innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend innodb_doublewrite=ON innodb_file_format=Barracuda innodb_file_per_table=ON innodb_flush_log_at_trx_commit=1 innodb_flush_method=O_DIRECT innodb_io_capacity=1000 innodb_lock_wait_timeout=10 innodb_log_buffer_size=67108864 innodb_log_file_size=1048576000 innodb_log_files_in_group=4 innodb_max_dirty_pages_pct=60 innodb_open_files=60000 innodb_purge_threads=1 innodb_read_io_threads=4 innodb_stats_on_metadata=OFF innodb_support_xa=ON innodb_use_native_aio=OFF innodb_write_io_threads=10
3307的配置以下:
[client] port=3307 socket=/data/my3307/mysql.sock [mysql] pid_file=/data/my3307/run/mysqld.pid [mysqld] autocommit=1 general_log=off explicit_defaults_for_timestamp=true # system basedir=/data/my3306 datadir=/data/my3307/data max_allowed_packet=1g max_connections=3000 max_user_connections=2800 open_files_limit=65535 pid_file=/data/my3307/run/mysqld.pid port=3307 server_id=101 skip_name_resolve=ON socket=/data/my3307/run/mysql.sock tmpdir=/data/my3307/tmp #binlog log_bin=/data/my3307/log/binlog/binlog binlog_cache_size=32768 binlog_format=row expire_logs_days=7 log_slave_updates=ON max_binlog_cache_size=2147483648 max_binlog_size=524288000 sync_binlog=100 #logging log_error=/data/my3307/log/error.log slow_query_log_file=/data/my3307/log/slow.log log_queries_not_using_indexes=0 slow_query_log=1 log_slave_updates=ON log_slow_admin_statements=1 long_query_time=1 #relay relay_log=/data/my3307/log/relaylog relay_log_index=/data/my3307/log/relay.index relay_log_info_file=/data/my3307/log/relay-log.info #slave slave_load_tmpdir=/data/my3307/tmp slave_skip_errors=OFF #innodb innodb_data_home_dir=/data/my3307/log/iblog innodb_log_group_home_dir=/data/my3307/log/iblog innodb_adaptive_flushing=ON innodb_adaptive_hash_index=ON innodb_autoinc_lock_mode=1 innodb_buffer_pool_instances=8 #default innodb_change_buffering=inserts innodb_checksums=ON innodb_buffer_pool_size= 128M innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend innodb_doublewrite=ON innodb_file_format=Barracuda innodb_file_per_table=ON innodb_flush_log_at_trx_commit=1 innodb_flush_method=O_DIRECT innodb_io_capacity=1000 innodb_lock_wait_timeout=10 innodb_log_buffer_size=67108864 innodb_log_file_size=1048576000 innodb_log_files_in_group=4 innodb_max_dirty_pages_pct=60 innodb_open_files=60000 innodb_purge_threads=1 innodb_read_io_threads=4 innodb_stats_on_metadata=OFF innodb_support_xa=ON innodb_use_native_aio=OFF innodb_write_io_threads=10 [mysqld_safe] datadir=/data/my3307/data
參考:
http://blog.csdn.net/kadwf123/article/details/79145700
http://blog.csdn.net/mchdba/article/details/45798139