MySQL 有三種安裝方式:RPM安裝、二進制包安裝、源碼包安裝。咱們這篇文章以二進制方式安裝MySQLhtml
軟件名稱 | 版本 |
---|---|
系統版本 | CentOS Linux release 7.2.1511 (Core) |
MySQL | mysql-5.7.18-linux-glibc2.5-x86_64 |
MySQL Installation Layout for Generic Unix/Linux Binary Packagejava
Directory | Contents of Directory |
---|---|
bin | mysqld server, client and utility programs |
docs | MySQL manual in Info format |
man | Unix manual pages |
include | Include (header) files |
lib | Libraries |
share | Error messages, dictionary, and SQL for database installation |
support-files | Miscellaneous support files |
配置項 | 說明 |
---|---|
config | /etc/my.cnf |
datadir | /data/mysql/mysql3306/data |
binlogdir | /data/mysql/mysql3306/logs |
tmpdir | /data/mysql/mysql3306/tmp |
/data 在生產環境中這個目錄最好是一個單獨掛載的一個分區mysql
server-id 爲了防止server-id衝突,咱們規定是主機IP地址的最後一位+MySQL監聽的端口號。例如個人IP是192.168.1.100 MySQL監聽的端口爲3306 ,因此個人server-id = 1003306linux
# yum install libaio -y
國內源:sql
# wget -P /opt/ http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
國外源:數據庫
# wget -P /opt/ https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
# useradd -s /sbin/nologin -M mysql
# mkdir /opt/mysql/ # tar zxf /opt/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /opt/mysql/ # cd /usr/local/ # ln -s /opt/mysql/mysql-5.7.18-linux-glibc2.5-x86_64 mysql
# mkdir -pv /data/mysql/mysql3306/{data,logs,tmp}
# chown -R mysql.mysql /usr/local/mysql # chown -R mysql.mysql /data
咱們使用的配置文件爲:/etc/my.cnfcentos
# cat > /etc/my.cnf << EOF ###### base ###### #my.cnf [client] port = 3306 socket = /tmp/mysql3306.sock [mysql] prompt="\u@\h [\d]>" no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data tmpdir = /data/mysql/mysql3306/tmp port = 3306 socket = /tmp/mysql3306.sock event_scheduler = 0 #timeout interactive_timeout = 300 wait_timeout = 300 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 lower_case_table_names =1 ###### GTID ###### gtid-mode = on enforce-gtid-consistency=1 ###### symi replication ###### #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=1 ####### slow log ###### log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log log_warnings = 2 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 ####### binlog ###### binlog_format = row server-id = 1003306 log-bin = /data/mysql/mysql3306/logs/mysql-bin max_binlog_size = 256M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 ####### relay log ###### skip_slave_start = 1 max_relay_log_size = 128M relay_log_purge = 1 relay_log_recovery = 1 relay-log=relay-bin relay-log-index = relay-bin.index log_slave_updates = ON #slave-skip-errors=1032,1053,1062 #skip-grant-tables ####### buffers & cache ###### table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 200 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 100M innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:100M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT EOF
# cd /usr/local/mysql # ./bin/mysqld --defaults-file=/etc/my.cnf --initialize
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # /etc/init.d/mysqld start
# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile # source /etc/profile
查看初始密碼:運維
# grep "password" /data/mysql/mysql3306/data/error.log 2017-05-08T07:49:40.620503Z 1 [Note] A temporary password is generated for root@localhost: q=8jh*JpNar)
初始密碼爲: q=8jh*JpNar) 每次初始化密碼都不會相同;
登陸數據庫修改密碼爲:unixfbi.comsocket
# mysql -uroot -p初始密碼 mysql> alter user user() identified by 'unixfbi.com'; 或者: mysql> SET PASSWORD=PASSWORD('unixfbi.com'); mysql> flush privileges;
或者:ide
# PASSWD=$(grep 'password is' /data/mysql/mysql3306/data/error.log | awk '{print $NF}') # mysql -uroot -p"$PASSWD" --connect-expired-password -e "alter user user() identified by 'unixfbi.com';"
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
http://database.51cto.com/art/201108/285365.htm
本文出自 「運維特工」 博客,轉載請務必保留原文連接 和 http://www.unixfbi.com