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

MySQL在线、离线安装

1、安装MySQL

(1)在线安装

[root@localhost Mysql]# dnf install mysql-server

(2)离线安装

获取安装包

[root@localhost ~]# ll
total 975916
-rw-r--r--  1 root root 999311360 Feb 26 17:50 mysql-8.0.36-1.el8.x86_64.rpm-bundle.tar

2、创建路径并解压

[root@localhost ~]# mkdir /Mysql
[root@localhost ~]# tar -xf mysql-8.0.36-1.el8.x86_64.rpm-bundle.tar -C /Mysql/
[root@localhost ~]# cd /Mysql
[root@localhost Mysql]# ll
total 975916
-rw-r--r-- 1 7155 31415  16734240 Dec 14  2023 mysql-community-client-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415  32183048 Dec 14  2023 mysql-community-client-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   3724348 Dec 14  2023 mysql-community-client-plugins-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   3534396 Dec 14  2023 mysql-community-client-plugins-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415    683892 Dec 14  2023 mysql-community-common-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   3699208 Dec 14  2023 mysql-community-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415  25187132 Dec 14  2023 mysql-community-debugsource-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   7911104 Dec 14  2023 mysql-community-devel-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   2347336 Dec 14  2023 mysql-community-icu-data-files-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   1564796 Dec 14  2023 mysql-community-libs-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415   2640980 Dec 14  2023 mysql-community-libs-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415  67559076 Dec 14  2023 mysql-community-server-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415  25954052 Dec 14  2023 mysql-community-server-debug-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415 161003740 Dec 14  2023 mysql-community-server-debug-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415 244094580 Dec 14  2023 mysql-community-server-debuginfo-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415 376738224 Dec 14  2023 mysql-community-test-8.0.36-1.el8.x86_64.rpm
-rw-r--r-- 1 7155 31415  23729176 Dec 14  2023 mysql-community-test-debuginfo-8.0.36-1.el8.x86_64.rpm

3、安装依赖

[root@localhost Mysql]# yum install mysql-community-server-8.0.36-1.el8.x86_64.rpm yum install mysql-community-client-8.0.36-1.el8.x86_64.rpm  mysql-community-common-8.0.36-1.el8.x86_64.rpm mysql-community-icu-data-files-8.0.36-1.el8.x86_64.rpm  yum install mysql-community-client-plugins-8.0.36-1.el8.x86_64.rpm  mysql-community-libs-8.0.36-1.el8.x86_64.rpm

4、启动服务

[root@localhost Mysql]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

5、查看服务状态

[root@localhost Mysql]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2025-02-26 18:04:17 CST; 12s ago
    Process: 2186 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 2208 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 2286 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 21400)
     Memory: 464.2M
     CGroup: /system.slice/mysqld.service
             └─ 2286 /usr/libexec/mysqld --basedir=/usr

Feb 26 18:04:10 localhost.localdomain systemd[1]: Starting MySQL 8.0 database server...
Feb 26 18:04:10 localhost.localdomain mysql-prepare-db-dir[2208]: Initializing MySQL database
Feb 26 18:04:17 localhost.localdomain systemd[1]: Started MySQL 8.0 database server.

6、 查看端口

[root@localhost Mysql]# netstat -lnupt | grep 3306
tcp6       0      0 :::33060                :::*                    LISTEN      2286/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      2286/mysqld

 前提安装 net-tools

[root@localhost Mysql]# yum install net-tools

在线安装无需密码可直接进入MySQL

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, 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>

离线安装需要获取密码

[root@localhost Mysql]# grep -i password /var/log/mysql.log
2025-02-26T10:55:23.740726Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;inS=:oe7DeZ
[root@localhost Mysql]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log
;inS=:oe7DeZ

7、修改密码

mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.01 sec)

8、再次登入MySQL并查看数据库

[root@localhost ~]# mysql -u root -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> \q

9、如无需输入密码直接进入MySQL

[root@localhost ~]# vim /etc/my.cnf
[client]
user=root
password=123456
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, 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>

相关文章:

  • 计算机毕业设计SpringBoot+Vue.js社区医院信息平台(源码+文档+PPT+讲解)
  • Nginx安装并配置https
  • RTSP/Onvif安防平台EasyNVR接入EasyNVS显示服务缺失的原因与解决方案
  • 阿里云ack的创建与实战应用案例
  • 音乐游戏Pump It Up(PIU)模拟器
  • Pytorch使用手册--将 PyTorch 模型导出为 ONNX(专题二十六)
  • 日本IT|Python开发工程师的职业前景
  • 第一 二章 小车硬件介绍-(全网最详细)基于STM32智能小车-蓝牙遥控、避障、循迹、跟随、PID速度控制、视觉循迹、openmv与STM32通信、openmv图像处理、smt32f103c8t6
  • 航旅纵横测试开发一面面经
  • Spring基础01
  • DOM 事件 HTML 标签属性速查手册
  • Remainder Problem CF1207F
  • APNG格式图片文件大小优化方案 转WEBP
  • 品牌全链路电商代运营:行业格局与头部服务商解析
  • 数据存储:一文掌握存储数据到ElasticSearch详解
  • 【监督学习】ARIMA预测模型步骤及matlab实现
  • 【Web世界探险家】CSS美学(一)
  • 【REST2SQL】15银河麒麟系统下达梦数据库部署REST2SQL
  • springboot015基于SpringBoot的在线视频教育平台的设计与实现(源码+数据库+文档)
  • 音频进阶学习十六——LTI系统的差分方程与频域分析一(频率响应)
  • 模板设计建站/商业策划公司十大公司
  • 手机wap网站制作/清博舆情系统
  • 网站开发及建设费用/网站营销软文
  • 网站建设与应用 教案/搜索引擎的优化和推广
  • 网站用什么语言/找文网客服联系方式
  • 在域名做网站/百度指数查询手机版app