CentOS Linux 7系统中离线安装MySQL5.7步骤

预计数据文件存储目录为:/opt/mysql/data

1、文件下载:

安装文件下载链接:https://downloads.mysql.com/archives/community/

2、检查当前系统是否安装过MySQL

[root@cnic51 mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@cnic51 mysql]# sudo rpm -e --nodeps mariadb-libs
警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave
[root@cnic51 mysql]# rpm -qa|grep mariadb
[root@cnic51 mysql]#

3、将MySQL安装包拷贝到linux服务器的/opt/temp/目录下

[root@hadoop54 temp]# ll
总用量 570706
-rw-r--r-- 1 root root  570705920 6月  20 13:45 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar [root@hadoop54 temp]#

4、解压MySQL安装包

[root@cnic51 temp]# tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.44-1.el7.x86_64.rpm
mysql-community-common-5.7.44-1.el7.x86_64.rpm
mysql-community-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-server-5.7.44-1.el7.x86_64.rpm
mysql-community-test-5.7.44-1.el7.x86_64.rpm
[root@cnic51 temp]#

5、在安装目录下执行rpm安装,按顺序安装

[root@cnic51 temp]# sudo rpm -ivh mysql-community-common-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.44-1.el7################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-compat-5.7.4################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-client-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-server-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.44-1.e################################# [100%]
[root@cnic51 temp]#

6、修改/etc/my.cnf文件中datadir指向的目录下的所有内容,如果有内容的情况下:
查看datadir的值,将其修改为如下:

旧的内容为:

# 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

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

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

新的内容为:

# 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
skip-name-resolve
basedir=/opt/mysql
datadir=/opt/mysql/data
max_connections=2000
port=3306
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
socket=/var/lib/mysql/mysql.sock

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

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

删除/var/lib/mysql目录下的所有内容(如果指定的目录不是默认的可以不用管):
[root@hadoop54 mysql]# cd /var/lib/mysql
[root@hadoop54 mysql]# ls
[root@hadoop54 mysql]# sudo rm -rf *
[root@hadoop54 mysql]#

7、初始化数据库

[root@hadoop51 mysql]# sudo chown -R mysql:mysql /opt /mysql
[root@hadoop51 mysql]# sudo mysqld --initialize --user=mysql
[root@hadoop51 mysql]#

8、查看临时生成的root帐号密码
2024-06-20T06:17:53.912194Z 0 [ERROR] Can't find error-message file '/opt/mysql/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2024-06-20T06:17:54.145587Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-06-20T06:17:54.220326Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-06-20T06:17:54.287423Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d45d6ffd-2ecc-11ef-a74a-fa081328b000.
2024-06-20T06:17:54.295842Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-06-20T06:17:55.180876Z 0 [Warning]
2024-06-20T06:17:55.180891Z 0 [Warning]
2024-06-20T06:17:55.184006Z 0 [Warning] CA certificate ca.pem is self signed.
2024-06-20T06:17:55.315891Z 1 [Note] A temporary password is generated for root@localhost: 8<A.-MrijeiF

9、启动MySQL数据库
[root@hadoop51 mysql]#  sudo systemctl start mysqld

10、登录MySQL数据库

[root@cnic51 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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 = password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'dev'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'dev'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

必须先修改root用户的密码,否则执行其他的操作会报错
mysql> set password = password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

11、根据需要是否修改mysql库下的user表中的root用户允许任意ip连接
mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

新建账号及授权语句:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dev'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'dev'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

  • 25
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值