Linux 安装 MySQL 8.0.26

news2024/10/7 4:31:22

1、MySQL 8.0.26 下载

官方网站下载 MySQL 8.0.26 安装包,下载地址:mysql8.0.26

在这里插入图片描述
本案例采用Linux 64位操作系统进行讲解,通过wget命令下载安装包。
使用df -lh命令查看,磁盘大小,尽量安装在比较大的磁盘下,防止空间不够使用。

[root@VM-0-4-centos home]# df -lh
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        3.9G     0  3.9G   0% /dev
tmpfs           3.9G   24K  3.9G   1% /dev/shm
tmpfs           3.9G  604K  3.9G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1        50G  3.8G   44G   9% /
tmpfs           783M     0  783M   0% /run/user/0

通过上述命令可以看出根目录空间比较充足,那么就把安装包下载到home目录了,执行wget命令。

[root@VM-0-4-centos home]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2、解压缩文件

解压 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 文件,使用tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 命令。

[root@VM-0-4-centos home]# tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz  
mysql-8.0.26-linux-glibc2.12-x86_64/bin/
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysql
....
mysql-8.0.26-linux-glibc2.12-x86_64/share/
mysql-8.0.26-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-8.0.26-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql

3、移动文件

将压缩包移动到usr/local目录下,并重命名文件为mysql,使用mv /home/mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql命令。

[root@VM-0-4-centos home]# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@VM-0-4-centos home]# cd /usr/local/mysql/
[root@VM-0-4-centos mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@VM-0-4-centos mysql]# cd ..
[root@VM-0-4-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  qcloud  sbin  share  src  yd.socket.server
[root@VM-0-4-centos local]#

4、创建数据存放目录

在mysql根目录下新建一个目录data,主要用于存放数据库数据文件,使用mkdir data命令。

[root@VM-0-4-centos local]# cd mysql/
[root@VM-0-4-centos mysql]# mkdir data
[root@VM-0-4-centos mysql]# ls
bin  data  docs  include  lib  LICENSE  man  README  share  support-files
[root@VM-0-4-centos mysql]#

5、创建用户组和用户

创建mysql用户组和mysql用户,使用groupadd mysql和useradd -g mysql mysql命令。

[root@VM-0-4-centos mysql]# groupadd mysql
[root@VM-0-4-centos mysql]# useradd -g mysql mysql

6、改变mysql目录权限

修改mysql目录权限,可以使用chown -R mysql.mysql /usr/local/mysql/命令。
在这里插入图片描述
修改mysql目录权限也可以通过chown -R mysql .和chgrp -R mysql .两个命令。注意:这两个命令都需要执行的,还有那个点不要忽视掉。

7、数据库初始化

数据库初始化./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize命令,得到临时密码。

[root@VM-0-2-centos mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2022-01-16T07:32:18.729960Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2022-01-16T07:32:18.729960Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 7691
2022-01-16T07:32:18.740975Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-16T07:32:19.800287Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-16T07:32:21.721672Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-01-16T07:32:21.722106Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-01-16T07:32:21.787669Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :e0l?pC>Z%R.

需要注意:记录一下mysql数据库的临时密码:e0l?pC>Z%R.,后面安装步骤是需要使用的,否则需要重新安装数据库或其他方式获取密码,此处问题省略。

8、修改my.cnf文件

修改my.cnf文件,使用vim /etc/my.cnf命令。

[mysqld]
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    socket = /usr/local/mysql/mysql.sock
    character-set-server=utf8
    port = 3306
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 [client]
    socket = /usr/local/mysql/mysql.sock
    default-character-set=utf8
#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
 
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d

直接将上述配置内容复制到my.cnf文件中,或者自行修改,然后执行:wq命令,保存并退出。

9、创建mysql服务

1)将mysql.server启动文件复制到/etc/init.d目录,使用cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld命令。

2)赋予权限,使用chmod +x /etc/rc.d/init.d/mysqld命令;

3)使用chkconfig --add mysqld创建mysql服务。

[root@VM-0-4-centos mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@VM-0-4-centos mysql]# chmod +x /etc/rc.d/init.d/mysqld 
[root@VM-0-4-centos mysql]# chkconfig --add mysqld

检查mysql服务是否生效,使用chkconfig --list mysqld命令。

[root@VM-0-4-centos mysql]# chkconfig  --list mysqld
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

10、配置全局环境变量

编辑/etc/profile文件,使用vim /etc/profile命令,在profile文件中添加如下两行配置,使用:wq命令保存后退出。

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

在这里插入图片描述
设置环境变量立即生效使用source /etc/profile命令。

[root@VM-0-4-centos ~]# source /etc/profile
[root@VM-0-4-centos ~]#

11、启动mysql服务

启动mysql服务,使用service mysql start命令;使用service mysql status命令,查看是否启动成功。

[root@VM-0-4-centos ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@VM-0-4-centos ~]# service mysql status
Redirecting to /bin/systemctl status mysql.service
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Sun 2022-01-16 17:17:55 CST; 8s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 27231 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           ├─27242 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM-0-4-centos.pid
           └─27408 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM-0-4-cent...
 
Jan 16 17:17:54 VM-0-4-centos systemd[1]: Starting LSB: start and stop MySQL...
Jan 16 17:17:54 VM-0-4-centos mysqld[27231]: Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-4-centos.err'.
Jan 16 17:17:55 VM-0-4-centos mysqld[27231]: SUCCESS!
Jan 16 17:17:55 VM-0-4-centos systemd[1]: Started LSB: start and stop MySQL.

12、登录mysql修改密码

登录mysql数据库,使用mysql -uroot -p密码命令,临时密码是:e0l?pC>Z%R.

[root@VM-0-4-centos ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26
 
Copyright (c) 2000, 2021, 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>

修改mysql临时密码,也就是将第七步数据库初始化生成的临时密码修改成自己需要设置的密码。
修改mysql数据库密码,使用ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;命令。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql>

注意:此处123456修改为自己的需要密码即可。

13、设置mysql远程登录

1)切换数据库,使用use mysql;命令。

2)修改mysql库中host值,使用update user set host=‘%’ where user=‘root’ limit 1;命令。

3)刷新mysql权限,使用flush privileges;命令。

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql>

14、mysql客户端连接数据库

客户端连接mysql数据库,连接名(自定义名称)、主机(IP)、端口号及用户名和密码,点击测试连接按钮,显示连接成功即可。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1870961.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

猫狗识别—静态图像识别

猫狗识别—静态图像识别 1. 导入必要的库:2. 设置数据目录和模型路径:3. 定义图像转换4. 使用GPU5. 加载没有预训练权重的ResNet模型6. 创建Tkinter窗口:7.定义选择图片的函数:8.定义预测图片的函数:9.退出程序的函数:10.创建按钮:11.运行Tkinter事件循环:12. 完整代码&#xf…

不止是只有维度建模,数据仓库还有Data Vault建模

引言 在数据仓库设计中,传统的星型和雪花型模型有着各自的优势和劣势。随着数据量的增大和数据源的多样化,Data Vault(数据仓库)建模方法逐渐受到关注和应用。Data Vault建模是一种灵活、可扩展、适应性强的建模方法,…

视频多功能闪剪助手,智能去重去水印一键剪辑

这款软件具有全平台去水印的功能,无论视频来自哪个平台,无论水印的位置如何变换,它都能轻松去除。同时,它还支持各种去重方法,无论重复内容的形式如何,它都能一一识别并移除,让你的视频内容始终…

HarmonyOS Next开发学习手册——层叠布局 (Stack)

概述 层叠布局(StackLayout)用于在屏幕上预留一块区域来显示组件中的元素,提供元素可以重叠的布局。层叠布局通过 Stack 容器组件实现位置的固定定位与层叠,容器中的子元素依次入栈,后一个子元素覆盖前一个子元素&…

SpringCloud Alibaba Sentinel规则持久化实践总结

默认情况下&#xff0c;一旦我们重启应用&#xff0c;sentinel规则将消失&#xff0c;生产环境需要将配置规则进行持久化。这里我们实践将Sentinel持久化到Nacos中。 ① pom依赖 我们引入sentinel-datasource-nacos&#xff1a; <dependency><groupId>com.aliba…

【Android Studio】Notification通知提醒功能完整代码以及踩坑记录

前言&#xff1a;在最近学习安卓通知功能的开发中&#xff0c;遇到了一些坑&#xff0c;困扰了我一些时间&#xff0c;搜集了大量资料写个博客总结一下&#xff0c;希望对大家有帮助。 目录 一、启动项目闪退 1.1、问题详情 1.2、解决方法 二、点击通知无法跳转 2.1、问题…

计算机缺失OpenCL.dll怎么办,OpenCL.dll丢失的多种解决方法

在使用电脑的过程中&#xff0c;我们经常会遇到一些开机弹窗问题。其中&#xff0c;开机弹窗找不到OpenCL.dll是一种常见的情况。本文将详细介绍开机弹窗找不到OpenCL.dll的原因分析、解决方法以及预防措辞&#xff0c;帮助大家更好地解决这一问题。 一&#xff0c;了解OpenCL.…

[AIGC] Doris:一款高效的MPP数据仓库引擎

在大数据处理的领域中&#xff0c;Apache Doris&#xff08;原百度 Palo&#xff09;是一个高效的MPP&#xff08;大规模并行处理&#xff09;数据仓库&#xff0c;最初由百度开发&#xff0c;现在已经成为Apache的孵化项目。 (图片取自百度) – 文章目录 1. Doris的基础知识…

并发 多线程

目录 thread thread 类总览 构造函数 join joinable ​编辑 detach swap yield swap 成员函数的调用 namespace::this_thread 线程同步--锁 互斥锁mutex 递归锁recursive_mutex 定时锁 Lock 锁辅助类 lock_guard​编辑 unique_lock std::lock 解决死锁问题 消息…

华为认证hcna题库背诵技巧有哪些?hcna和hcia有什么区别?

大家都知道华为认证hcna是有题库供考生刷题备考的&#xff0c;但题库中海量的题目想要在短时间背诵下来可并不是一件容易的事情&#xff0c;这就需要我们掌握一定的技巧才行。华为认证hcna题库背诵技巧有哪些? hcna和hcna这二者又有什么区别呢?今天的文章将为大家进行详细解…

鸿蒙开发设备管理:【@ohos.batteryInfo (电量信息)】

电量信息 该模块主要提供电池状态和充放电状态的查询接口。 说明&#xff1a; 本模块首批接口从API version 6开始支持。后续版本的新增接口&#xff0c;采用上角标单独标记接口的起始版本。 导入模块 import batteryInfo from ohos.batteryInfo;属性 描述电池信息。 系统能…

汇川学习笔记7 - 雕刻机项目

1、系统上电轴准备好之后&#xff0c;自动复回原点一次&#xff0c; 2、在雕刻机面板上有三个按钮用来控制画三种图形 3、注意cnc代码放置的文件夹 4、FILE0文件内容 5、FILE1文件内容 6、FILE2文件内容 7、程序代码下载地址 https://download.csdn.net/download/qq_6191667…

设置日历程序

目录 一 设计原型 二 后台源码 一 设计原型 二 后台源码 namespace 设置日历 {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void dateTimePicker1_ValueChanged(object sender, EventArgs e){richTextBox1.Text dateTimePicker1.T…

CCSP自考攻略+经验总结

备考攻略 备考攻略准备阶段通读阶段精度阶段总复习阶段刷题阶段命运审判 写到最后 备考攻略 趁着对ssp知识点的理解还在&#xff0c;开始ccsp的考证之路&#xff0c;文章结构还是按照cissp备考篇的结构梳理。本次备考和cissp的离职在家备考不同&#xff0c;ccsp是在职利用非工…

鸿蒙开发Ability Kit(程序框架服务):【ServiceAbility切换】 组件切换

ServiceAbility切换 FA模型中的ServiceAbility对应Stage模型中的ServiceExtensionAbility。Stage模型下的ServiceExtensionAbility为系统API&#xff0c;只有系统应用才可以创建。因此&#xff0c;FA模型的ServiceAbility的切换&#xff0c;对于系统应用和三方应用策略有所不同…

【深度学习】实践方法论

李宏毅深度学习笔记 优化问题 训练数据的损失不够低的时候&#xff0c;到底是模型偏差&#xff0c;还是优化的问题&#xff1f; 判断方法是通过比较不同的模型来判断模型现在到底够不够大 看到一个从来没有做过的问题&#xff0c;可以先跑一些比较小的、比较浅的网络&#x…

React@16.x(42)路由v5.x(7)常见应用场景(4)- 路由切换动画

目录 1&#xff0c;实现路由切换基础样式 2&#xff0c;使用 CSSTransition 添加动画1&#xff0c;自定义动画组件 *TransitionRoute.jsx*2&#xff0c;*App.jsx*3&#xff0c;样式改动 3&#xff0c;注意点 通过一个例子来说明如何实现。 1&#xff0c;实现路由切换 基础样式…

【Linux:文件描述符】

文件描述符&#xff1a; 文件描述符的分配原则&#xff1a;最小未分配原则 每一个进程中有一个task_struct结构体&#xff08;PCB)&#xff0c;而task_struct中含有struct file_sturct*file的指针&#xff0c;该指针指向了一个struct files_struct的结构体该结构体中含有一个f…

win10系统打开Windows更新是空白的如何解决?

最近装wsl的时候&#xff0c;遇到了这个问题。查阅了很多相关资料&#xff0c;发现导致wsl --install安装不了的主要原因都集中在于windows更新组件损坏导致的&#xff0c;经过排查&#xff0c;我的这个组件确实不能够正常使用&#xff0c;可能是因为之前使用了windows激活工具…

网络治理新模式:Web3时代的社会价值重构

随着Web3技术的崛起&#xff0c;传统的网络治理模式正在经历革新&#xff0c;这不仅仅是技术的进步&#xff0c;更是对社会价值观念的挑战和重构。本文将深入探讨Web3时代的网络治理新模式&#xff0c;其背后的技术基础、社会影响以及未来的发展方向。 1. 引言 Web3时代&#…