MySQL 8.0/5.7 linux 安装

1.安装前说明

  • 本文档仅适用于MySQL 8.0/5.7 glibc版的安装使用,请使用官方的安装包进行安装。
  • 操作系统建议版本:
    • centos 6.x/7.x
    • redhat 6.x/7.x
    • oracle linux 6.x/7.x
  • 数据库版本要求:
    • MySQL 5.7.14+
    • MySQL 8.0.12+
  • Mysql安装路径(以下目录不需提前创建):
    • mysql软件主目录:/usr/local/mysql
    • mysql数据文件目录:/var/lib/mysql
    • mysql其他日志,socket文件存放目录:/var/lib/mysql

2.安装包下载

  • 官网下载地址:https://dev.mysql.com/downloads/mysql/
  • 根据linux系统位数下载最新的Linux-Generic安装包
  • 5.7请点击 looking for previous GA versions选择5.7版本下载即可

3.上传安装包并使用root用户登入系统

通过ftp或者ssh等文件传输工具将下载得来的安装包上传至服务器

通过客户端工具使用root用户连接到服务器

 4.安装依赖包创建mysql用户

libaio属于建议安装的系统包,该功能可以提高数据库的IO性能

系统自带的有yum源可以使用yum安装或者使用系统自带的镜像进行RPM安装

[root@localhost ~]# yum install libaio -y     

注:没有配置yum可使用rpm安装,rpm安装命令:rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(安装包下载对应系统版本的即可)

创建mysql用户和用户组

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql

5.上传并解压安装包(上传路径没有要求)

[root@localhost ~]# cp mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz /usr/local/

[root@localhost local]# cd /usr/local/

[root@localhost local]# xz -d mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

[root@localhost local]# tar xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar

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

[root@localhost local]# cd mysql

[root@localhost mysql]# chown mysql:mysql -R /usr/local/mysql/*

6.初始化数据库

复制文档最后附件中的my.cnf替换/etc/my.cnf(如果没有该文件可直接创建一个新的即可)或单独编辑配置文件,在[mysqld]一栏下方新增以下参数:

[root@localhost ~]# vi /etc/my.cnf


character-set-server=utf8
max_connections = 5000                     ###动态参数,根据实际的用户量进行调整即可,最低要求500

log_bin_trust_function_creators=1
lower_case_table_names = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
transaction_isolation = READ-COMMITTED
group_concat_max_len = 102400

初始化数据库,安装加密算法,并启动数据库(初始化过程有随机的root密码,注意输出信息)

[root@localhost mysql]# cd /usr/local/mysql

[root@localhost mysql]# bin/mysqld --initialize --user=mysql

注意此处的系统输出信息中包含系统默认的root用户密码,请记录下来。

安装加密算法

[root@localhost mysql]# bin/mysql_ssl_rsa_setup

7.注册数据库服务

[root@localhost mysql]# cd /usr/local/mysql

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# chmod +x /etc/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

8.启动mysql服务

[root@localhost mysql]#service mysqld start

9.配置数据库的sock文件,并修改root用户的初始密码

[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p

Enter password: 输入随机生成的密码(即步骤6记录下来的密码)

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12
Copyright (c) 2000, 2018, 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 = 'mysqltest123';
Query OK, 0 rows affected (0.01 sec)

10.创建ecology数据库,并创建账号,赋权

mysql>create database ecology;
mysql> create user ecology identified with mysql_native_password by 'ecology123';
mysql> grant all privileges on *.* to 'ecology'@'%';
mysql> flush privileges
注:8.0的用户管理方式与以往版本变动较大,要注意使用官方手册。

11.停止mysql服务

[root@localhost mysql]#service mysqld stop

附:my.cnf

[mysqld]

user=mysql

port = 3306

datadir = /var/lib/mysql

 

character-set-server=utf8

server-id = 1

max_connections = 5000

max_connect_errors = 10

table_open_cache = 4096

event_scheduler = ON

skip-name-resolve

lower_case_table_names = 1

group_concat_max_len = 102400

 

max_allowed_packet = 64M

binlog_cache_size = 32M

max_heap_table_size = 256M

read_rnd_buffer_size = 64M

sort_buffer_size = 256M

join_buffer_size = 512M

thread_cache_size = 300

log_bin_trust_function_creators=1

key_buffer_size = 256M

read_buffer_size = 32M

read_rnd_buffer_size = 128M

bulk_insert_buffer_size = 512M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

######READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE

transaction_isolation = READ-COMMITTED

tmp_table_size = 512M

log-bin=mysql-bin

binlog_format=mixed

expire_logs_days = 60

slow_query_log = 1

slow_query_log_file = /var/lib/mysql/slow.log

long_query_time = 5

 

####### InnoDB

innodb_buffer_pool_size = 512M

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 32M

innodb_log_file_size = 1024M

innodb_log_files_in_group = 4

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

#innodb_force_recovery=1

 

[mysqldump]

quick

max_allowed_packet = 64M

 

[mysql]

no-auto-rehash

 

[myisamchk]

key_buffer = 16M

sort_buffer_size = 16M

read_buffer = 8M

write_buffer = 8M

 

[mysqlhotcopy]

interactive-timeout

 

[mysqld_safe]

open-files-limit = 65535

log-error=/var/lib/mysql/mysqld.log

pid-file=/var/lib/mysql/mysqld.pid
THE END
分享
二维码
打赏
海报
MySQL 8.0/5.7 linux 安装
1.安装前说明 本文档仅适用于MySQL 8.0/5.7 glibc版的安装使用,请使用官方的安装包进行安装。操作系统建议版本:centos 6.x/7.xredhat 6.x/7.xoracle lin……
<<上一篇
下一篇>>