mysql的linux安装tar.gz

一. 准备资源
1.准备资源,去官网下载mysql的tar包

1.1点击进入官网地址:https://dev.mysql.com/downloads/

1.2 选择community

1.3 选择5.7对应的版本下载

1.4.上传tar包到服务器

/usr/local/

2.或者拉取

    wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

二.开始安装
3.卸载系统自带的Mariadb
    [root@node01 ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.44-2.el7.centos.x86_64
    [root@node01 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

4.删除etc目录下的my.cnf文件

    [root@node01 ~]# rm -rf  /etc/my.cnf
    rm: cannot remove ?etc/my.cnf? No such file or directory

5.检查mysql是否存在
    [root@node01 ~]# rpm -qa | grep mysql
    [root@node01 ~]#

6.检查mysql组和用户是否存在,如无创建
    [root@node01 ~]# cat /etc/group | grep mysql
    [root@node01 ~]#  cat /etc/passwd | grep mysql

7.创建mysql用户组

[root@node01 ~]# groupadd mysql
8.创建一个用户名为mysql的用户并加入mysql用户组
    [root@node01 ~]# useradd -g mysql mysql
9.制定password 为111111
    [root@node01 ~]# passwd mysql
    Changing password for user mysql.
    New password:
    BAD PASSWORD: The password is a palindrome
    Retype new password:
    passwd: all authentication tokens updated successfully.

10.准备解压安装/usr/local

    root@node01 local]# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
    [root@node01 local]# mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql57
 
    #更改所属的组和用户
    [root@node01 local]# chown -R mysql:mysql mysql57/

11 在etc下新建配置文件my.cnf,并在该文件内添加以下配置

1.

    [mysql]
    # 设置mysql客户端默认字符集
    default-character-set=utf8
    [mysqld]
    skip-name-resolve
    #设置3306端口
    port = 3306
    # 设置mysql的安装目录
    basedir=/usr/local/mysql57
    # 设置mysql数据库的数据的存放目录
    datadir=/usr/local/mysql57/data
    # 允许最大连接数
    max_connections=200
    # 服务端使用的字符集默认为8比特编码的latin1字符集
    character-set-server=utf8
    # 创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB
    lower_case_table_names=1
    max_allowed_packet=16M

2.

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/export/servers/mysql57/
# 设置mysql数据库的数据的存放目录
datadir=/export/servers/mysql57/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M

server_id=1
log-bin=/export/servers/mysql57/binlog/log-bin
binlog_format=row

gtid_mode =on

#设置为主从强一致性
enforce-gtid-consistency=1
log-slave-updates=1

3.

# Server System Variables
# https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html


[client]
#host=localhost
#port=3306
#user=root
#password=xxxxxx
#default-character-set=utf8  # utf8mb4


[mysql]
prompt="(\\u@\\h \R:\m:\\s)[\\d]> "
#pager="less -i -n -S"
tee="/export/servers/mysql57/log/mysql-history.log"
no-auto-rehash
#default_character_set=utf8  # utf8mb4


[mysqld]
basedir=/export/servers/mysql57/
datadir=/export/servers/mysql57/data

socket=/export/servers/mysql57/data/mysql.sock
pid-file=/export/servers/mysql57/data/mysqld.pid

#secure-file-priv=NULL
secure-file-priv=/export/servers/mysql57/log

user=mysql

port=3306

# Administrative Connection Management
# https://dev.mysql.com/doc/refman/8.0/en/administrative-connection-interface.html
#admin_address=127.0.0.1
#admin_port=33062
#create_admin_listener_thread=ON

server_id=1017134080

#auto_increment_offset=1
#auto_increment_increment=2

# caching_sha2_password Compatibility Issues and Solutions
# https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issues
#default_authentication_plugin=mysql_native_password  # caching_sha2_password (default)

#federated

# MySQL Server Time Zone Support
# https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html
default-time-zone='+8:00'

# Character-set
#init_connect='SET NAMES utf8mb4'
#init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci; INSERT INTO auditdb.tb_audit(thread_id,log_time,log_user,dbuser,dbname) VALUES(connection_id(),now(),user(),current_user(),database());'
character_set_server=utf8  # utf8mb4
collation_server=utf8_general_ci  # utf8mb4_unicode_ci

# SQL Mode
# https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_mode
#sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#sql_mode="ALLOW_INVALID_DATES,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,HIGH_NOT_PRECEDENCE,IGNORE_SPACE,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_UNSIGNED_SUBTRACTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY,PAD_CHAR_TO_FULL_LENGTH,PIPES_AS_CONCAT,REAL_AS_FLOAT,STRICT_ALL_TABLES,STRICT_TRANS_TABLES"
sql_mode=''

# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_sql_require_primary_key
#sql_require_primary_key=ON

#sql_safe_updates=ON
#sql_warnings=ON

autocommit=1
lower_case_table_names=1
explicit_defaults_for_timestamp=0
ft_min_word_len=4

bind_address=0.0.0.0

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# name-resolve
skip_external_locking=ON
skip_name_resolve=ON
skip_networking=OFF
skip_show_database=OFF
#host_cache_size=0

# Monitor
performance_schema=ON

# Event
event_scheduler=ON

# Replication Filter
#replicate_do_db=test
#replicate_wild_do_table=test.%
#replicate_ignore_db=test
#replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
replicate_wild_ignore_table=sys.%
replicate_wild_ignore_table=auditdb.%

# Plugins
plugin_dir=/export/servers/mysql57/lib/plugin/
#plugin_load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
plugin_load_add="validate_password=validate_password.so"

# Password Validation Plugin Options and Variables
# https://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html
validate-password=FORCE_PLUS_PERMANENT
validate_password_policy=MEDIUM
validate_password_length=12  # 8(default)
validate_password_mixed_case_count=1
validate_password_number_count=1
validate_password_special_char_count=1
validate_password_check_user_name=ON
#validate_password_dictionary_file=

# Semi sync replication settings
#loose_rpl_semi_sync_master_enabled=ON
#loose_rpl_semi_sync_master_timeout=1000
#loose_rpl_semi_sync_slave_enabled=ON

# Slave
#slave_net_timeout=60
slave_parallel_type=LOGICAL_CLOCK
# cat /proc/cpuinfo | grep "processor" | wc -l
slave_parallel_workers=4
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

# GTID
gtid_mode=on
enforce_gtid_consistency=on
log_slave_updates=1

# Binary Log
#disable-log-bin  # skip-log-bin
log_bin=/export/servers/mysql57/log/mysql-bin
binlog_format=ROW
binlog_row_image=FULL  # FULL (default), MINIMAL
binlog_rows_query_log_events=OFF  # OFF (default)
sync_binlog=1000  # 0(default), 1(safe), N(recommended)
binlog_cache_size=2097152  # 2097152=2MB
max_binlog_cache_size=18446744073709547520
max_binlog_size=524288000  # 524288000=500MB
log_bin_trust_function_creators=ON
expire_logs_days=7
# https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds
#binlog_expire_logs_seconds=2592000  # 2592000 = 30 days (default), 604800 = 7 days

# Relay Log
relay-log=/export/servers/mysql57/log/mysql-relay-bin
relay_log_purge=1

# https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_log_timestamps
# This variable controls the time zone of timestamps in messages written to the error log, and in general query log and slow query log messages written to files.
# It does not affect the time zone of general query log and slow query log messages written to tables (mysql.general_log, mysql.slow_log).
# Rows retrieved from those tables can be converted from the local system time zone to any desired time zone with CONVERT_TZ() or by setting the session time_zone system variable.
log_timestamps=SYSTEM

# https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_log_output
# The destination or destinations for general query log and slow query log output. The value is a list one or more comma-separated words chosen from TABLE, FILE, and NONE.
# TABLE selects logging to the general_log and slow_log tables in the mysql system database. FILE selects logging to log files. NONE disables logging.
# If NONE is present in the value, it takes precedence over any other words that are present. TABLE and FILE can both be given to select both log output destinations.
log_output=FILE

# Error Log
log_error=/export/servers/mysql57/log/mysql-error.log

# Slow Log
slow_query_log=ON
slow_query_log_file=/export/servers/mysql57/log/mysql-slow.log
long_query_time=1
log_slow_admin_statements=ON
log_slow_slave_statements=OFF
log_queries_not_using_indexes=ON
log_throttle_queries_not_using_indexes=10

# General Log
#general_log=ON  # OFF(Default)
general_log_file=/export/servers/mysql57/log/mysql-general.log

# Audit Log
#server_audit=FORCE_PLUS_PERMANENT
#server_audit_events='CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL'
#server_audit_logging=OFF
#server_audit_file_path=/export/servers/mysql57/log/server_audit.log
#server_audit_file_rotate_size=100000000
#server_audit_file_rotations=10
#server_audit_file_rotate_now=ON

# Connections
max_connections=4532
max_user_connections=4000
max_connect_errors=100
back_log=3000  # 151(Default)
thread_cache_size=256  # 9(Default)

# Per connection: 256kb
sort_buffer_size=868352
read_buffer_size=868352
read_rnd_buffer_size=442368
join_buffer_size=442368
thread_stack=262144

interactive_timeout=7200
wait_timeout=86400

## Limit
net_buffer_length=16384  # 16384=16KB, 16384(Default), 1048576=1MB(Maximum)
max_allowed_packet=1073741824  # 1073741824=1GB, 67108864(Default)
slave_max_allowed_packet=1073741824

max_prepared_stmt_count=16382
open_files_limit=65535
table_open_cache=2000

bulk_insert_buffer_size=4194304  # 4194304=4MB

#tmpdir=/tmp
tmpdir=/export/servers/mysql57/log
tmp_table_size=2097152
max_heap_table_size=16777216  # 16777216=16MB

key_buffer_size=16777216  # 16777216=16MB

## InnoDB Engine
#innodb_force_recovery=0
default_storage_engine=InnoDB
innodb_file_per_table=ON
#innodb_data_file_path=ibdata1:1G:autoextend
#innodb_data_file_path=ibdata1:12M;ibdata2:1G:autoextend
innodb_data_file_path=ibdata1:460M:autoextend  # RDS parameter
# 75% Total Memory
innodb_buffer_pool_size=8G
# 25% of buffer pool size
#innodb_log_file_size=48MB  # 1048576000=1000MB
innodb_log_file_size=1048576000  # 1048576000=1000MB
#innodb_log_file_size=1572864000  # 1572864000=1500MB, RDS parameter
innodb_flush_log_at_trx_commit=2  # 0, 1(Safe), 2(Recommended)
innodb_flush_method=O_DIRECT
# cat /proc/cpuinfo | grep "processor" | wc -l
#innodb_read_io_threads=2
#innodb_write_io_threads=2
#innodb_io_capacity=2000
#innodb_io_capacity_max=4000
# Where binlog_format: STATEMENT-1, ROW-2
innodb_autoinc_lock_mode=1

## RDS
innodb_checksum_algorithm=crc32
#innodb_log_checksum_algorithm=strict_crc32
#innodb_data_file_path=ibdata1:200M:autoextend
innodb_log_files_in_group=2
#innodb_log_file_size=1572864000
#innodb_fast_checksum=false
#innodb_page_size=16384
#innodb_log_block_size=512
innodb_undo_directory=./
innodb_undo_tablespaces=0
#server_id=1011584124
#redo_log_version=1
#server_uuid=abd944f6-daff-11eb-956c-506b4b1d4aee
#master_key_id=0
#innodb_encrypt_algorithm=AES_256_CBC


[mysqldump]
quick
net_buffer_length=16384  # 16384=16KB, 16384(Default), 1048576=1MB(Maximum)
max_allowed_packet=1073741824  # 1073741824=1GB, 67108864(Default)

12. 安装和初始化

 如下和my.cnf的配置保持一致

--basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data

这个貌似无法启动

    [root@node01 mysql57]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data

新的启动方式:

bin/mysqld --defaults-file=/etc/my.cnf --basedir=/export/servers/mysql57 --datadir=/export/servers/mysql57/data --user=mysql --initialize

当执行报错请安装,centos6资源已经丢失,启用centos7资源

 wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm

 rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm

13.重启

vim support-files/mysql.server

basedir=/export/servers/mysql57
datadir=/export/servers/mysql57/data

之后

  cp support-files/mysql.server /etc/init.d/mysqld

    [root@node01 mysql57]# /etc/init.d/mysqld restart
    Shutting down MySQL.. SUCCESS!
    Starting MySQL. SUCCESS!

14.设置开机启动

[root@node01 mysql57]# chkconfig --level 35 mysqld on
[root@node01 mysql57]# chkconfig --list mysqld

[root@node01 mysql57]# chmod +x /etc/rc.d/init.d/mysqld
[root@node01 mysql57]# chkconfig --add mysqld
[root@node01 mysql57]# chkconfig --list mysqld
[root@node01 mysql57]# service mysqld status
 SUCCESS! MySQL running (4475)

15.设置环境变量vim /etc/profile/

    export PATH=$PATH:/var/mysql57/bin
     
    [root@node01 mysql57]# source /etc/profile

16. 获得初始密码

    [root@node01 bin]# cat /root/.mysql_secret  
    # Password set for user 'root@localhost' at 2017-04-17 17:40:02
    _pB*3VZl5T<6

17. 修改密码

    [root@node01 bin]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.7.18
     
    Copyright (c) 2000, 2017, 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> set PASSWORD = PASSWORD('111111');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
     
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)

18 .添加远程访问权限

    在本机先使用root用户登录mysql: mysql -u root -p"youpassword" 进行授权操作:
     
    mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
     
    重载授权表:
     
    FLUSH PRIVILEGES;
     
    退出mysql数据库:
     
    exit

19.重启生效

    /bin/systemctl restart  mysql.service
     
    [root@node01 bin]# /etc/init.d/mysqld restart
    Shutting down MySQL.. SUCCESS!
    Starting MySQL. SUCCESS!

20. 为了在任何目录下可以登录mysql

ln -s /usr/local/mysql57/bin/mysql   /usr/bin/mysql

三.开启外部访问数据库

21. 开放防火墙端口

firewall-cmd --list-all

22.开放3306端口

firewall-cmd --permanent --add-port=3306/tcp

23.查看3306端口是否开放

firewall-cmd --query-port=3306/tcp

24.次查看现在防火墙

firewall-cmd --list-all

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值