centos7.4源碼安裝mysql5.6.38

1、環境centos7 x64
CentOS Linux release 7.4.1708 (Core) 關閉selinux
下載 https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz
yum install gcc gcc-c++ ncurses-devel cmake libaio bison perl-Module-Install.noarch -y
2、權限
建立用戶
#useradd -r -g mysql -s /sbin/nologin -M mysql
數據庫存放目錄設置成mysql用戶mysql組
mkdir -p /data/mysqldata/3306用來存放數據庫並賦予權限
chown -R mysql.mysql /data/mysqldata/3306
3、編譯mysql5.6.38.tar.gz,解壓 tar zxvf mysql5.6.38.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3306 -DMYSQL_DATADIR=/data/mysqldata/3306 -DSYSCONFDIR=/usr/local/mysql3306/etc -DMYSQL_UNIX_ADDR=/usr/local/mysql3306/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
然後執行
make && make install

4、編譯完成配置mysql服務權限
# cd /usr/local/mysql3306
# chown -R mysql:mysql .
# mkdir -p /data/mysql
# mkdir -p /usr/local/mysql3306/etc
# chown mysql.mysql -R /data
# chmod 775 -R /data

scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql3306 --datadir=/data/mysqldata/3306/
和配置my.cnf 保持一致
#### chown -R root:mysql . (將權限設置給root用戶,並設置給mysql組, 取消其他用戶的讀寫執行權限,僅留給mysql "rx"讀執行權限,其他用戶無任何權限)
## chown -R mysql:mysql ./data (數據庫存放目錄設置成mysql用戶mysql組)
## chmod -R ug+rwx . (賦予讀寫執行權限,其他用戶權限一律刪除僅給mysql用戶權限)

# cp support-files/my-default.cnf /usr/local/mysql3306/etc/my.cnf (可以放在/etc/my.cnf)
修改my.cnf配置,先使用簡單配置,測試數據庫正常後,再增加優化配置
# vi /etc/my.cnf
#[mysqld] 下面添加:
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql3306
datadir=/data/mysqldata/3306
port=3306
socket=/data/mysqldata/3306/mysql.sock
server_id=1
[mysqld_safe]
log-error=/data/mysqldata/3306/log/mysqld.log
備註修改 datadir=/data/mysqldata/3306 需要在 scripts/mysql_install_db --user=mysql 添加 --datadir=/data/mysqldata/3306
5、 啓動mysql
# bin/mysqld_safe --user=mysql &
看是否成功
# ps –ef|grep mysql**

將mysql的啓動服務添加到系統服務中
# cp support-files/mysql.server /etc/init.d/mysql3306
現在可以使用下面的命令啓動mysql
# service mysql3306 start
停止mysql服務
# service mysql3306 stop
重啓mysql服務
# service mysql3306 restart

6、修改root用戶密碼
# cd /usr/local/mysql3306
# ./bin/mysqladmin -u root password
New password:
Confirm new password:
回車在接下來的提示中設置新密碼即可。。
# service mysql3306 restart; (重啓mysql服務器)

7、登錄mysql測試
#cd
#vim .bash_profile
修改.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql3306/bin
然後source .bash_profile
#mysql -uroot -p
mysql> use mysql;
mysql> select host,user from mysql.user;

8、我這生產環境下my.cnf配置
#
##mysql configure file my.cnf
#
[client]
port = 3306
socket = /usr/local/mysql3306/mysql.sock

[mysql]
prompt="\u@mysqldb \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql3306
datadir = /data/mysqldata/3306
socket = /usr/local/mysql3306/mysql.sock
pid-file = /data/mysqldata/datasql-2.pid
character-set-server = utf8
lower_case_table_names=1
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 2000
max_connect_errors = 1000000
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 3000
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/mysqldata/3306/log/slow.log
log-error = /data/mysqldata/3306/log/mysqld.log
long_query_time = 0.1
log_queries_not_using_indexes =1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
server-id = 43 #主從複製加上次參數,數值可以按IP末尾數,也可以其他值
log-bin = mysql-bin #主從複製加上次參數
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

log_bin_trust_function_creators = 1
transaction_isolation = REPEATABLE-READ

innodb_buffer_pool_size = 91750M #參考服務器內存情況,按內存的80%填寫
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1

innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2

# 根據您的服務器IOPS能力適當調整
# 普通SSD盤的話,可以調整到 10000 - 20000
#高端PCIe SSD卡的話,調整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4

innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32

innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G

innodb_stats_on_metadata = 0

innodb_status_file = 1
# 開啓 innodb_status_output & innodb_status_output_locks , 可能會導致log-error文件增長較快
innodb_status_output = 0
innodb_status_output_locks = 0

#performance_schema
performance_schema = 1
performance_schema_instrument = '%=on'

#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"

[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error = /data/mysqldata/3306/log/mysqld.log
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章