First, download the MySQL binary packages
Some may ask: Why binary packages?
Mainly because the binary package has all the features are configured Well!
Production or test environment will generally choose the GA version (commonly available version, after restoration bug tested)
Download command:
# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
Or their own website to download Quguan
URL https://dev.mysql.com/downloads/
As shown below:
MD5 checksum carried out after the download is complete, make sure the package without any problems during the download process, can be used normally:
# md5sum mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
Second, the environment detection system before installation
In order to be successful in the MySQL database installed, do database optimization work late, a Linux-based system in the early detection of very necessary!
1, turn off SELinux and firewall systems
The SELinux set to disabled, restart the system after setting
# vim /etc/selinux/config
7 SELINUX=disabled
Close firewalld firewall
# systemctl stop firewalld
# systemctl disable firewalld
# systemctl mask firewalld.service
Install iptables
# yum install iptables-services.x86_64 -y
# systemctl status iptables
2, swap partition settings
Swappiness size has a great influence on the value of the swap partition
- 0 represents the maximum physical memory before you use the swap partition, which may cause the system out of memory, OOM error, causing accidents kill off the mysql
- 100 is a positive use of swap partitions, and timely data to memory above moved swap partition.
- Not recommended allocation swap or 4GB of space allocated
View swappiness file
# cat /proc/sys/vm/swappiness
30
# sysctl -a | grep swap
vm.swappiness = 30
Option 3, the file system
It recommended xfs, compared to ext4, easier to manage, support for dynamic expansion.
4, the operating system restrictions
View the current limit on your operating system
# ulimit -a
注意
open files (-n) 1024
max user processes (-u) 7179
Modify the software and hardware limitations of the system, to avoid limiting the reasons being given!
# vim /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
- After the changes, the need to restart the operating system to take effect
5, closed numa
Close numa function, you can better allocate memory, no way to get the use of swap memory (swap will lead to database performance degradation)
Three, MySQL5.7 installation
1, the establishment of mysql user
# groupadd mysql
# useradd -g mysql mysql -s /sbin/nologin
2, unzip, soft links
/ Usr / local / directory as base
# cd /usr/local/
Decompression
# tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
Be soft links, easy to upgrade in the future
to mysql directory permissions
# ln -s mysql-5.7.26-linux-glibc2.12-x86_64 mysql
# chown mysql:mysql -R mysql
3, establish a data directory
- General authorization is required to establish that the specified directory
# mkdir -p /data/mysql/
# chown -R mysql:mysql /data/mysql/
4, edit the configuration file
- Because it is a binary file, database configuration files here need to configure their own good
# vim /etc/my.cnf
#my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\\u@\\h [\\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log
no-auto-rehash
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /data/mysql/mysqld_multi.log
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0
tmpdir = /data/mysql/
#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
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = /data/mysql/slow.log
log-error = /data/mysql/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 = STATEMENT
binlog_format = row
server-id = 1003306
log-bin = /data/mysql/mysql-bin
binlog_cache_size = 4M
max_binlog_size = 256M
max_binlog_cache_size = 1M
sync_binlog = 0
expire_logs_days = 10
#procedure
log_bin_trust_function_creators=1
#
gtid-mode = 0
#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
#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 = 1024M
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_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = REPEATABLE-READ
innodb_flush_method = O_DIRECT
5. Start the database
# cd /usr/local/mysql/bin
#初始化
# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize
#启动
#./mysqld_safe --defaults-file=/etc/my.cnf &
- -Initialize represents a temporary database initialization generated password, which is recorded in log-error
-initialize-insecure indicates no password entered
6, landing database
View initial password
# cat /data/mysql/error.log | grep password
Landed
# ./mysql -u root -p
7, reset the password
root@localhost [(none)]>SET PASSWORD = 'root123'; #更改密码
root@localhost [(none)]>ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; #永不过期
root@localhost [(none)]>flush privileges; #刷新权限
8, shut down the MySQL database
Normally closed
# cd /usr/local/mysql/bin/
# ./mysqladmin -uroot -proot123 shutdown
Non-normal shutdown process needs to kill off MySQL
For convenience, the environment variables will join Mysql
# vim /etc/profile
PATH="$PATH":/usr/local/mysql/bin #加入
# source /etc/profile