CentOS 7.8 offline installation of MySQL (take MySQL5.7 as an example)

1. Download the MySQL5.7 rpm package

mysql5.7 download address
mysql8.0 download address

Two, installation and configuration

Mount the iso image and install it as a dependency package; mysql-community-server depends on net-tools and perf. If you have already installed vim, you don’t need to install perf. (Vim depends on perf)

mkdir /media/CentOS
mount -t iso9660 -o ro,loop /opt/CentOS-7-x86_64-DVD-1810.iso /media/CentOS
ls /media/CentOS
yum --disablerepo=\* --enablerepo=c7-media install -y net-tools perf

Install MySQL

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -ivh ./mysql-community-common-5.7.31-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-libs-5.7.31-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-client-5.7.31-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-server-5.7.31-1.el6.x86_64.rpm

Open port 3306

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

Turn off SeLinux

setenforce 0
getenforce
vi /etc/selinux/config
# enforcing修改为disabled
SELINUX=disabled

Three, configure MySQL

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

user=mysql
skip-name-resolve

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

lower_case_table_names=1
sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Fourth, modify the MySQL data directory

cd /home
mkdir -p /home/data/mysql
chown -R mysql:mysql data/mysql

vi /etc/my.cnf
# 修改datadir数据目录(记得关闭SeLinux)
# datadir=/var/lib/mysql
datadir=/home/data/mysql

Note: If you have already initialized MySQL, you need to copy the original data directory to the new data directory, and then start the MySQL service.

cd /home/data/mysql
cp -pr /var/lib/mysql/* .

Five, start MySQL and modify the root password

When MySQL is started for the first time, MySQL will be initialized. Therefore, please try to configure the /etc/my.cnf file once. Avoid extra work steps.

#查看自动生成的临时密码
cat /var/log/mysqld.log |grep password
查询结果如下:
2020-09-03T07:51:34.045157Z 1 [Note] A temporary password is generated for root@localhost: ZuoOejf5Vj#d

#登录
mysql -uroot -p'ZuoOejf5Vj#d'

mysql> grant all privileges on *.* to 'root'@'localhost' identified by '123456' with grant option;
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
mysql> flush privileges;

MySQL 8.0 does not support the creation of users while granting, and you need to create users before authorization.

修改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; 
修改密码并指定加密方式:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> flush privileges;

创建用户:
mysql> create user  'root'@'%' identified by '123456';
mysql> grant all on *.* to 'root'@'%' WITH GRANT OPTION;;
mysql> flush privileges;

Six, start MySQL and set the boot to start

systemctl enable mysqld
systemctl start mysqld

Guess you like

Origin blog.csdn.net/ory001/article/details/108385542