Ubuntu20.04 离线安装 MySQL 5.7

原文:https://blog.csdn.net/emergencysun/article/details/124229238

 

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

二、介质下载
1.安装依赖包
libmecab2 http://archive.ubuntu.com/ubuntu/pool/universe/m/mecab/libmecab2_0.996-1.2ubuntu1_amd64.deb
libaio1 http://archive.ubuntu.com/ubuntu/pool/main/liba/libaio/libaio1_0.3.110-2_amd64.deb
libtinfo5 http://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.2-0ubuntu2_amd64.deb
2.MySQL下载
首先,打开MySQL产品下载页面:
产品页面
其次,选择操作系统对应的社区版本,此处以64位 Ubuntu 20.04.4 LTS操作系统为例,选择选择Ubuntu Linux
18.04 (x86, 64-bit), DEB Bundle:下载链接
三、依赖及MySQL安装
将下列4个已下载文件拷贝至服务器 /home/myuser/soft 目录

mysql-server_5.7.34-1ubuntu18.04_i386.deb-bundle.tar
ibtinfo5_6.2-0ubuntu2_amd64.deb
libmecab2_0.996-1.2ubuntu1_amd64.deb
libaio1_0.3.110-2_amd64.deb
1.安装依赖包,依次执行命令:

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

2.安装MySQL
解压 mysql-server_5.7.34-1ubuntu18.04_i386.deb-bundle.tar命令:

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

依次执行以下命令进行安装:

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

检查MySQL的安装:

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

**备注:**安装了MySQL 8.0的无法降级安装5.7.x,需要卸载MySQL 8.0以后再安装MySQL 5.7.x 。

四、MySQL 配置
1.MySQL 初始化
MySQL安全完毕后,重启服务器,执行以下命令进行MySQL初始化操作:

sudo mysql_secure_installation
// 建议选择:不会进行密码的强校验,不修改root密码,不删除匿名用户,允许root远程连接,删除test数据库

检查MySQL 状态,执行命令:

sudo systemctl status mysql.service

2.MySQL 访问默认配置
修改mysqld.cnf配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
// 注释bind-address = 127.0.0.1

允许root 远程访问,根据实际情况修改

mysql -u root -p //输入密码
use mysql //选择访问mysql库
update user set host = '%' where user = 'root'; //使root能再任何host访问
FLUSH PRIVILEGES; //刷新

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

sudo ufw allow 3306/tcp

3.配置参考:mysqld.cnf
MySQL 参数配置文件 /etc/mysql/mysql.conf.d/mysqld.cnf ,参考配置如下:

# 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

 

posted @ 2024-06-14 14:26  Tozhang  阅读(176)  评论(0编辑  收藏  举报