MySQL5.7 二进制安装

解压MySQL5.7二进制包

[root@localhost tmp]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

[root@localhost tmp]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

将解压后的文件放到指定目录

[root@localhost tmp]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql

*注意* 目录"/usr/local/mysql"必须不存在,否则会被拷贝到此目录下

查看文件是否拷贝完全

[root@localhost tmp]# ll /usr/local/mysql
total 40
drwxr-xr-x  2 mysql mysql  4096 Mar 14 22:11 bin
-rw-r--r--  1 mysql mysql 17987 Dec 21 18:39 COPYING
drwxr-xr-x  2 mysql mysql    55 Mar 14 22:11 docs
drwxr-xr-x  3 mysql mysql  4096 Mar 14 22:10 include
drwxr-xr-x  5 mysql mysql  4096 Mar 14 22:11 lib
drwxr-xr-x  4 mysql mysql    30 Mar 14 22:11 man
-rw-r--r--  1 mysql mysql  2478 Dec 21 18:39 README
drwxr-xr-x 28 mysql mysql  4096 Mar 14 22:11 share
drwxr-xr-x  2 mysql mysql    90 Mar 14 22:11 support-files

创建mysql用户

[root@localhost tmp]# useradd mysql

创建所需目录并更改属主和属组

[root@localhost tmp]# mkdir -p /data/mysql/data
[root@localhost tmp]# mkdir -p /data/mysql/logs
[root@localhost tmp]# chown mysql:mysql -R /data
[root@localhost tmp]# chown mysql:mysql -R /usr/local/mysql

编辑参数文件

[root@localhost tmp]# cat > /etc/my.cnf <<EOF
[mysqld]
# basic settings #
user = mysql
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY"
character_set_server=utf8mb4
collation_server=utf8mb4_bin
default-storage-engine=innodb
pid-file=/data/mysql/data/mysql.pid
socket=/tmp/mysql.sock
basedir= /usr/local/mysql
datadir=/data/mysql/data
tmpdir=/tmp
transaction-isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
lower_case_table_names=1
max_allowed_packet = 32M
slave_pending_jobs_size_max = 32M
event_scheduler = 1
server-id=1383306
port=3306
symbolic-links=0
sysdate-is-now
show_compatibility_56=on
back_log=1000
# connection #
interactive_timeout = 200
wait_timeout = 200
lock_wait_timeout = 1800
skip_name_resolve = 1
max_connections = 2000
max_connect_errors = 100000

# table cache performance settings #(??)
table_open_cache = 3000
table_definition_cache = 4096
table_open_cache_instances = 16

# session memory settings #(??)
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 4M
tmp_table_size = 100M
max_heap_table_size = 100M
join_buffer_size = 4M
thread_cache_size = 64
# log settings #
general_log_file=/data/mysql/logs/general.log
log-error=/data/mysql/logs/error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file=/data/mysql/logs/slow-query.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
binlog-rows-query-log-events = 1
log-bin=/data/mysql/data/mysql-bin
log-bin-index=/data/mysql/data/mysql-bin.index
log_bin_trust_function_creators = 1
binlog_cache_size=4M
max_binlog_cache_size = 4096M
max_binlog_size = 1024M
expire-logs-days=3
log-slave-updates = 1
relay-log-index=/data/mysql/data/mysql-relay-bin.index
relay-log=/data/mysql/data/mysql-relay-bin
log_timestamps=system
#log_warnings =2 #??????,?????log_error_verbosity=2
log_error_verbosity=2

# innodb settings #
innodb_page_size = 16384
innodb_data_home_dir=/data/mysql/data
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_buffer_pool_size = 1G  #(??)
innodb_buffer_pool_instances = 1
innodb_buffer_pool_dump_pct = 40
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 50
innodb_rollback_on_timeout=1
innodb_flush_log_at_trx_commit = 1
innodb_io_capacity = 200
innodb_max_dirty_pages_pct =75
innodb_io_capacity_max = 1000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_directory=/data/mysql/data #??,????
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_undo_log_truncate = 1 #????/??undo log ??truncate??
innodb_max_undo_log_size = 2G
innodb_purge_threads = 4
innodb_purge_rseg_truncate_frequency = 128 #?????????????,??????
innodb_flush_neighbors = 0 #ssd0,?ssd1
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_log_group_home_dir=/data/mysql/data
innodb_page_cleaners = 16
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_sync_spin_loops=0 #???????,?????CPU??
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
innodb_write_io_threads = 16  #(??)
innodb_read_io_threads = 16   #(??)
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size=1G
innodb_open_files=4096
loose_innodb_numa_interleave=1

# about query_cache #
query_cache_type=0
query_cache_size=0

# replication settings #
master_info_repository = TABLE
relay_log_info_repository = TABLE
sync_binlog = 1
sync-relay-log =0
sync-relay-log-info =0 #??relay_log_info_repository = TABLE,?mysql.slave_relay_log_info?innodb?,???????1,????innodb??N?
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = ROW
binlog_rows_query_log_events = 1
relay_log_recovery = 1
slave_parallel_workers=20
slave-parallel-type = LOGICAL_CLOCK
slave_transaction_retries=128
#slave_skip_errors = ddl_exist_errors
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
log-slave-updates=true
sync-master-info=1
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
slave_preserve_commit_order=1
read_only=0

# GTID settings #
gtid-mode=on
enforce-gtid-consistency=true
binlog_gtid_simple_recovery=1

# SEMI Replication setting
plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled =1
rpl_semi_sync_slave_enabled=1
rpl_semi_sync_master_timeout=5000

[mysqldump]
quick
max_allowed_packet = 32M

[mysqld_safe]
user=mysql
open-files-limit=65536
log-error=/data/mysql/logs/error.log
> EOF

配置环境变量

[root@localhost tmp]# vim /home/mysql/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

MYSQL_HOME=/usr/local/mysql

PATH=$MYSQL_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin

export PATH


[root@localhost tmp]# . /home/mysql/.bash_profile

初始化

[root@localhost tmp]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

启动mysqld实例

[root@localhost tmp]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

登录到mysql添加密码

[root@localhost tmp]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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.

[root@localhost][(none)]> grant all on *.* to root@localhost identified by "root";
Query OK, 0 rows affected, 2 warnings (5.01 sec)

[root@localhost][(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值