Install MySQL 5.7 offline on Ubuntu

1. The required environment

Operating system: Ubuntu  20.04
Database: MySQL 5.7.34
Network situation: Intranet server, unable to access Internet resources

2. Download the required installer and installation package in advance 

1. Required dependent packages

(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

2. Download the MySQL installation package

演示所用版本:
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/

3. Install dependencies and install MySQL

1. Upload the downloaded dependencies and installation packages to the folder you specify (/opt for demo)

2. Install dependent packages

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

3. Install MySQL

(1) Unzip the installation package

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

After decompression, the directory is as follows: 

(2) Install 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

(3) Verify that the MySQL installation is successful:

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

View mysql status:

sudo systemctl status mysql.service

Four, MySQL configuration

1. Enable MySQL remote access

(1) Modify the mysqld.cnf configuration file

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

打开文件后将下面一行注释
#bind-address = 127.0.0.1(修改后)

 (2) Execute the following command to enable remote access restriction (note: the IP enabled by the following command is 192.168.0.1, if you want to enable all, use % instead of IP):

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

Then enter the following two lines of commands

flush privileges; 
exit;

2. Open the port on the firewall 

1、查看防火墙状态,inactive是关闭,active是开启。
sudo ufw status

2、开启防火墙。
sudo ufw enable

3、关闭防火墙。
sudo ufw disable

4、开启3306端口访问
sudo ufw allow 3306/tcp

Note: UFW firewall develops port 3306. When UFW is in Status: inactive (sudo ufw status verbose), you don’t need to execute the above command

5. Configuration file reference

# 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

Supongo que te gusta

Origin blog.csdn.net/wd520521/article/details/127262726
Recomendado
Clasificación