当前位置:   article > 正文

Ubuntu离线安装 MySQL 5.7_ubuntu 离线安装 mysql5.7

ubuntu 离线安装 mysql5.7

安装mysql

一、所需环境
操作系统:Ubuntu 20.04
数据库:MySQL 5.7.34
网络情况:内网服务器,无法访问互联网资源

二、提前下载所需以来及安装包
1、所需依赖包

(1)libmecab2 
http://archive.ubuntu.com/ubuntu/pool/universe/m/mecab/libmecab2_0.996-1.2ubuntu1_amd64.deb
(2)libaio1 
http://archive.ubuntu.com/ubuntu/pool/main/liba/libaio/libaio1_0.3.110-2_amd64.deb
(3)libtinfo5 
http://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.2-0ubuntu2_amd64.deb
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2、下载MySQL安装包

演示所用版本:

https://cdn.mysql.com/archives/mysql-5.7/mysql-server_5.7.34-1ubuntu18.04_amd64.deb-bundle.tar

大家可以去官网下载自己需要的版本:
https://downloads.mysql.com/archives/community/
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述

三、安装依赖,以及安装MySQL
1、将下载的依赖以及安装包上传到自己指定的文件夹(演示用/opt)

2、安装依赖包

sudo dpkg -i libmecab2_0.996-1.2ubuntu1_amd64.deb
sudo dpkg -i libaio1_0.3.110-2_amd64.deb
sudo dpkg -i libtinfo5_6.2-0ubuntu2_amd64.deb
  • 1
  • 2
  • 3

3、安装MySQL

(1)解压安装包

sudo tar -xvf mysql-server_5.7.34-1ubuntu18.04_amd64.deb-bundle.tar
  • 1

解压后目录如下:

(2)安装MySQL

sudo dpkg -i mysql-common_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg-preconfigure mysql-community-server_5.7.34-1ubuntu18.04_amd64.deb    //此步需要输入数据的root密码
sudo dpkg -i libmysqlclient20_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqld-dev_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-client_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-client_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-common_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-server_5.7.34-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-server_5.7.34-1ubuntu18.04_amd64.deb
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

(3)验证MySQL的安装是否成功:

mysql -u root -p //输入密码

查看mysql状态:

sudo systemctl status mysql.service
  • 1

四、MySQL配置
1、开启MySQL远程访问

(1)修改mysqld.cnf配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
  • 1

打开文件后将下面一行注释
#bind-address = 127.0.0.1(修改后)
(2)执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.0.1,如要开启所有的,用%代替IP):

grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
  • 1

然后再输入下面两行命令

flush privileges; 
  • 1

exit;
2、防火墙开打开端口

1、查看防火墙状态,inactive是关闭,active是开启。
sudo ufw status
 
2、开启防火墙。
sudo ufw enable
 
3、关闭防火墙。
sudo ufw disable
 
4、开启3306端口访问
sudo ufw allow 3306/tcp
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

注意:UFW防火墙开发 3306端口,UFW处于 Status: inactive 时(sudo ufw status verbose),可以不执行上面操作命令

五、配置文件参考

# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
# ......
# ......
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
log-error	= /var/log/mysql/error.log
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 1024M
max_allowed_packet = 100G
table_open_cache = 4096
sort_buffer_size = 16M
net_buffer_length = 4K
read_buffer_size = 16M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 256M
thread_cache_size = 512
query_cache_size = 512M
tmp_table_size = 512M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 
explicit_defaults_for_timestamp = true
skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
 
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
#slow_query_log=1
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""
 
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 4096M
innodb_log_file_size = 2048M
innodb_log_buffer_size = 512M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 40
innodb_write_io_threads = 40
 
[mysqldump]
quick
max_allowed_packet = 500M
 
[mysql]
no-auto-rehash
 
[myisamchk]
key_buffer_size = 1024M
sort_buffer_size = 16M
read_buffer = 2M
write_buffer = 2M
 
[mysqlhotcopy]
interactive-timeout
 
# By default we only accept connections from localhost
# bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74

修改mysql配置文件
/etc/mysql/mysql.conf.d/mysqld.cnf

datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log
  • 1
  • 2

变更mysql数据库数据目录

参考文章

关停mysql服务

sudo systemctl stop mysql.service
  • 1

复制原有数据

cp -arp /var/lib/mysql  [新存储路径]
ps:参数a,只复制目录属性,不赋值数据;参数r,递归复制目录;参数p,保留文件全部的属性,可指定
  • 1
  • 2

修改权限

chown -R mysql:mysql [新存储路径]
//确保权限正确
  • 1
  • 2

修改配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉原来的:#datadir = /var/lib/mysql
修改成:datadir=[新存储路径]
  • 1
  • 2
  • 3

修改启动文件usr.sbin.mysqld

vim /etc/apparmor.d/usr.sbin.mysqld 
  • 1

将:

/var/lib/mysql r 
/var/lib/mysql/** rwk 
  • 1
  • 2

修改成:

[新存储路径] r 
[新存储路径]/** rwk 
  • 1
  • 2

重启服务:

/etc/init.d/apparmor restart  
sudo systemctl start mysql.service
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/555935
推荐阅读
相关标签
  

闽ICP备14008679号