当前位置: 首页 > news >正文

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)

相关文章:

  • Zabbix 7.0 LTS新特征
  • xss-lab靶场level1-level10
  • Centos7升级K8S集群
  • YOLOv10改进 | Neck | 添加双向特征金字塔BiFPN【含二次独家创新】
  • RK3568技术笔记十四 Ubuntu创建共享文件夹
  • 掌握心理学知识成为产品经理一门必修课?
  • 第一百一十六节 Java 面向对象设计 - Java 终止块
  • MySQL 常用函数总结
  • SAP 新安装的系统,财务开账期OB52需要传输
  • C++的智能指针 RAII
  • 【AI应用探讨】— 盘古大模型应用场景
  • 如何选择合适的半桥栅极驱动芯片?KP8530X,KP85402,KP85211A满足你对半桥栅极驱动一切需求
  • Oracle最终还是杀死了MySQL
  • 步步为营:电商项目业务测试实战指南
  • 考试系统Spring Security的配置
  • 《微软的软件测试之道》成书始末、出版宣告、补充致谢名单及相关信息
  • 【笔记】你不知道的JS读书笔记——Promise
  • 〔开发系列〕一次关于小程序开发的深度总结
  • Android Studio:GIT提交项目到远程仓库
  • canvas 高仿 Apple Watch 表盘
  • C学习-枚举(九)
  • docker python 配置
  • Linux快速复制或删除大量小文件
  • MD5加密原理解析及OC版原理实现
  • Python利用正则抓取网页内容保存到本地
  • Python语法速览与机器学习开发环境搭建
  • springboot_database项目介绍
  • Tornado学习笔记(1)
  • Travix是如何部署应用程序到Kubernetes上的
  • Unix命令
  • vue-loader 源码解析系列之 selector
  • Windows Containers 大冒险: 容器网络
  • windows-nginx-https-本地配置
  • XML已死 ?
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • Hibernate主键生成策略及选择
  • MyCAT水平分库
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • ###C语言程序设计-----C语言学习(3)#
  • #面试系列-腾讯后端一面
  • $.each()与$(selector).each()
  • (1)(1.13) SiK无线电高级配置(六)
  • (安全基本功)磁盘MBR,分区表,活动分区,引导扇区。。。详解与区别
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (附源码)计算机毕业设计高校学生选课系统
  • (三)Pytorch快速搭建卷积神经网络模型实现手写数字识别(代码+详细注解)
  • (十三)Java springcloud B2B2C o2o多用户商城 springcloud架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)...
  • (五)关系数据库标准语言SQL
  • (转)树状数组
  • *上位机的定义
  • .NET Micro Framework初体验(二)
  • .net mvc部分视图
  • .Net Web项目创建比较不错的参考文章
  • .NET 表达式计算:Expression Evaluator