概述

本文主要是写Ubuntu22.04搭建MySQL8.0.26版本

环境信息

IP 系统 规格
10.0.0.10 Ubuntu22.04 2c4g

数据库服务安装步骤

下载前置依赖

# 下载libtinfo5、libnuma1依赖
[root@lb ~]# apt update -y && apt install -y libtinfo5 libnuma1

服务下载

方式一:进入官网下载,并上传到宿主机中,适合离线环境

官网下载地址: https://downloads.mysql.com/archives/community/

方式二:直接在宿主机中使用wget进行下载,适合宿主机联网环境

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

服务解压并创建软链接

# 服务解压至家目录
[root@lb ~]# tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz # 创建软链接
[root@lb ~]# ln -s mysql-8.0.26-linux-glibc2.12-x86_64 mysql # 查看
[root@lb ~]# ll | grep mysql
lrwxrwxrwx 1 root root 35 May 1 15:43 mysql -> mysql-8.0.26-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 4096 May 1 15:43 mysql-8.0.26-linux-glibc2.12-x86_64/
-rw-r--r-- 1 root root 914806904 Jul 2 2021 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

配置环境变量

# /root/mysql/bin根据你安装的实际地址来进行替换
[root@lb ~]# echo 'export PATH=/root/mysql/bin:$PATH' >> /etc/profile
[root@lb ~]# source /etc/profile

检查环境变量是否配置正确

[root@lb ~]# mysql -V
mysql Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)

创建MySQL的虚拟用户

[root@lb ~]# useradd -s /sbin/nologin -M mysql

创建数据存储目录,并修改目录的拥有者

[root@lb ~]# mkdir -p /data/mysql/data
[root@lb ~]# chown -R mysql.mysql /data/mysql/data

初始化数据库

# 初始化数据库,没有报错即代表成功
[root@lb ~]# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql/data --basedir=/root/mysql
2025-05-01T07:59:04.638615Z 0 [System] [MY-013169] [Server] /root/mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 132486
2025-05-01T07:59:04.656989Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-05-01T07:59:05.254538Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-05-01T07:59:05.950015Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-05-01T07:59:05.950635Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-05-01T07:59:06.009584Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

参数解释:

  • --initialize-insecure:不安全的初始化,表示数据库启动后没有密码信息,
  • --initialize:安全初始化,表示数据库启动后,会有默认的密码信息
  • --user:指定用户
  • --datadir:指定数据存储目录
  • --basedir:指定MySQL安装的目录

数据库初始化成功之后数据目录会有以下文件

[root@lb ~]# ll /data/mysql/data/
total 177608
-rw-r----- 1 mysql mysql 196608 May 1 15:59 '#ib_16384_0.dblwr'
-rw-r----- 1 mysql mysql 8585216 May 1 15:59 '#ib_16384_1.dblwr'
drwxr-x--- 2 mysql mysql 4096 May 1 15:59 '#innodb_temp'/
drwxr-xr-x 6 mysql mysql 4096 May 1 15:59 ./
drwxr-xr-x 3 root root 4096 May 1 15:56 ../
-rw-r----- 1 mysql mysql 56 May 1 15:59 auto.cnf
-rw------- 1 mysql mysql 1676 May 1 15:59 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 May 1 15:59 ca.pem
-rw-r--r-- 1 mysql mysql 1112 May 1 15:59 client-cert.pem
-rw------- 1 mysql mysql 1680 May 1 15:59 client-key.pem
-rw-r----- 1 mysql mysql 5995 May 1 15:59 ib_buffer_pool
-rw-r----- 1 mysql mysql 50331648 May 1 15:59 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 1 15:59 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 May 1 15:59 ibdata1
drwxr-x--- 2 mysql mysql 4096 May 1 15:59 mysql/
-rw-r----- 1 mysql mysql 26214400 May 1 15:59 mysql.ibd
drwxr-x--- 2 mysql mysql 4096 May 1 15:59 performance_schema/
-rw------- 1 mysql mysql 1676 May 1 15:59 private_key.pem
-rw-r--r-- 1 mysql mysql 452 May 1 15:59 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 May 1 15:59 server-cert.pem
-rw------- 1 mysql mysql 1680 May 1 15:59 server-key.pem
drwxr-x--- 2 mysql mysql 4096 May 1 15:59 sys/
-rw-r----- 1 mysql mysql 16777216 May 1 15:59 undo_001
-rw-r----- 1 mysql mysql 16777216 May 1 15:59 undo_002

编写MySQL配置文件

[root@lb ~]# cat /etc/my.cnf
[mysqld]
# 数据库文件的存储路径
datadir=/data/mysql/data
# 服务器监听的端口号
port=3306
# 字符集设置
character-set-server=utf8mb4
# 排序规则
collation-server=utf8mb4_general_ci
# 允许的最大连接数
max_connections=1000
# MySQL服务器的缓存大小,用于缓存数据和索引
innodb_buffer_pool_size=1G
# 日志文件的路径
log_error=/var/log/mysql/error.log
# 慢查询日志文件的路径
slow_query_log_file=/var/log/mysql/slow-query.log
# 开启慢查询日志,1表示开启,0表示关闭
slow_query_log=1
# 设定慢查询的时间阈值,单位为秒,超过此时间的查询将被记录到慢查询日志中
long_query_time=3
# 设置用户
user=mysql
# 设置socket连信息
socket=/tmp/mysql.sock [client]
# 客户端默认字符集
default-character-set=utf8mb4 [mysql]
# MySQL命令行工具的默认字符集
default-character-set=utf8mb4

创建日志目录

[root@lb ~]# mkdir -p /var/log/mysql/
[root@lb ~]# chown -R mysql.mysql /var/log/mysql/

修改MySQL安装目录中的启动文件

拷贝启动文件至/etc/init.d目录下

[root@lb ~]# cp /root/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@lb ~]# chmod +x /etc/init.d/mysqld

修改启动文件的内容

vim /etc/init.d/mysqld

启动MySQL服务

# 没报错即代表启动成功
[root@lb ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl): mysqld.service. # 检查端口号
[root@lb ~]# ss -lntup | grep 3306
tcp LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=144896,fd=21))
tcp LISTEN 0 1000 *:3306 *:* users:(("mysqld",pid=144896,fd=24))

修改root用户密码

[root@lb ~]# mysqladmin -u root password "huangsir"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

登录MySQL服务

[root@lb ~]# mysql -uroot -phuangsir
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 10
Server version: 8.0.26 MySQL Community Server - GPL 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默认的root用户是无法远程登录的,所以我们需要创建一个用户用于远程登录

# 创建用户,10.0.0.0/24代表网段,只有在这个网段之内的IP才能连接数据库,密码设置为huangsir
mysql> CREATE USER 'root'@'10.0.0.0/24' IDENTIFIED BY 'huangsir';
Query OK, 0 rows affected (0.01 sec) # 授权,*.*代表所有的库和表
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.0.0.0/24' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec) # 刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

使用navicat连接数据库测试

Linux系统搭建单机MySQL8.0.26版本的更多相关文章

  1. 【web】 亿级Web系统搭建——单机到分布式集群

      当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的压力会越来越大,在这个过程中,我们会遇到很多的问题.为了解决这些性能压力带来问题,我们需要在Web系统架 ...

  2. Linux系统搭建Red5服务器

    Linux系统搭建Red5服务器 Red5 是 支持Windows,Linux等多平台的RTMP流媒体服务器,Windows下搭建相对容易,图形界面操作比较简单,Linux服务器的环境下没有图形界面, ...

  3. Linux系统部署规范v1.0

    Linux系统部署规范v1.0 目的: 1.尽可能减少线上操作: 2.尽可能实现自动化部署: 3.尽可能减少安装服务和启动的服务: 4.尽可能使用安全协议提供服务: 5.尽可能让业务系统单一: 6.尽 ...

  4. SpringMVC+MyBatis+Druid使用MySQL8.0.11版本

    1.使用MySQL8.0.11版本,要使用5.1.45或其他高版本驱动jar包,我本地使用的是最新的8.0.11 2.更换了MySQL驱动后,报Cannot find class [com.aliba ...

  5. Mysql8.0.17版本不能自动创建activiti表的坑

    maven项目如下: 配置好数据库,和activiti的配置之后,开始执行流程部署 package com.yuanqiao.first_activiti.deployment; import jav ...

  6. MYSQL8.0以上版本ROOT密码报错及修改

    在登录数据库过程中,如果遇到忘记root密码时,该如何解决? 1.使用管理员权限打开命令提示符,在命令行中输入: net stop mysql  2.待mysql服务停止后,输入: mysqld -- ...

  7. mysql8.0以上版本修改密码问题记录

    参考链接: https://blog.csdn.net/qq_27820551/article/details/101488430 https://blog.csdn.net/mukouping82/ ...

  8. linux测试系统使用expdp迁移数据到windos系统,11.2.0.4版本测试

    测试,使用linux 系统,迁移至windos测试系统,迁移用户scott 1.源端导出(linux) 2.传输 3.目标端导入(windows) 1.源端导出,本次使用expdp 1)创建操作系统转 ...

  9. 在Linux系统下安装大于mysql5.5版本的数据库

    linux下mysql 5.5的安装方法: 1.安装所需要系统库相关库文件      gcc等开发包,在安装linux系统的时候安装. 2.创建mysql安装目录 # mkdir -p /usr/lo ...

  10. Linux系统搭建Java环境【JDK、Tomcat、MySQL】一篇就够

      前言:所有项目在完成开发后都会部署上线的,一般都是用Linux系统作为服务器的,很少使用Windows Server(大多数项目的开发都是在Windows桌面系统完成的),一般有专门负责上线的人员 ...

随机推荐

  1. IDEA 打开多个文件显示在多行Tab上

    1.左上角选择Preferences 2.搜索Editor Tabs,右侧取消勾选Show tabs in one row

  2. 自己如何在本地电脑从零搭建DeepSeek!手把手教学,快来看看! (建议收藏)

    在人工智能飞速发展的今天,大语言模型的应用越来越广泛.DeepSeek 作为近期爆火的一款大语言模型,受到了众多开发者的青睐. 今天这篇内容,就来聊聊,如何在本地自己的电脑上部署DeepSeek. 1 ...

  3. redis的连接池和管道

    NoSQL泛指非关系型的数据库   非关系型数据库和关系型数据库的差别: 性能NOSQL是基于键值对的,可以想象成表中的主键和值的对应关系,而且不需要经过SQL层的解析,所以性能非常高 可扩展性同样也 ...

  4. 15. Docker容器监控之(CAdvisor+InfluxDB+Granfana)的详细安装和常规使用

    15. Docker容器监控之(CAdvisor+InfluxDB+Granfana)的详细安装和常规使用 @ 目录 15. Docker容器监控之(CAdvisor+InfluxDB+Granfan ...

  5. pagehelper分页查询的一个坑,明明下一页没有数据了却还是返回了数据

    pagehelper分页查询的一个坑,明明下一页没有数据了却还是返回了数据 解决:关闭这该死的合理化,如下配置: pagehelper:# helperDialect: mysql reasonabl ...

  6. NCS开发学习笔记-基础篇-第 1 课 – nRF Connect SDK 简介

    第 1 课 – nRF Connect SDK 简介 目标 了解 nRF Connect SDK 的结构和内容 在内部,nRF Connect SDK 代码分为四个主要存储库: nrf – 应用程序. ...

  7. Qt读取Oracle中的中文乱码问题

    Qt读取oracle中的中文 因为有的时候我们的oracle数据库里面的值是一个varchar2格式的,这就是一个ascii码,但是我们qt一般不是ascii码 解决方法如下 先使用utl_raw.c ...

  8. [tldr] 如何给自己的程序编写一个systemd服务

    参考Systemd 入门教程:实战篇 配置文件 systemd使用配置文件作为程序服务启动的方式,分为可以自启动的和不能自启动的 就是enable和start的命令的区别 分为/etc/systemd ...

  9. 介绍一个不知道怎么形容的小东西--Proxy

    what's this? The Proxy object is used to define custom behavior for fundamental operations (e.g. pro ...

  10. k8s报错Error: template: nvidia-device-plugin/templates/gfd.yml:22:19: executing "nvidia-device-plugin/templates/gfd.yml" at <.Subcharts.gfd>: nil pointer evaluating interface {}.gfd

    前言 在安装 kubernetes 插件 k8s-device-plugin时,报错: Error: template: nvidia-device-plugin/templates/gfd.yml: ...