在Ubuntu安装开源数据库MySQL 8.0版本


在Ubuntu 22.04上安装MySQL 8.0的步骤相对直接,可以使用APT包管理器从官方存储库中安装。
在这里插入图片描述

更新软件包列表

更新软件包列表:sudo apt-get update

mirror@mirror-Virtual-Machine:~$ sudo apt-get update 
获取:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
命中:2 http://archive.ubuntu.com/ubuntu jammy InRelease 
获取:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
获取:4 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1,109 kB]
命中:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
获取:6 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1,325 kB]
获取:7 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [207 kB]
获取:8 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [837 kB]
获取:9 http://security.ubuntu.com/ubuntu jammy-security/universe Translation-en [160 kB]        
获取:10 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1,042 kB]         
获取:11 http://archive.ubuntu.com/ubuntu jammy-updates/universe Translation-en [235 kB]        
已下载 5,145 kB,耗时 4(1,396 kB/s)                           
正在读取软件包列表... 完成

安装MySQL服务器

sudo apt-get install mysql mysql-server

在这里插入图片描述
但是会提示报错,无法定位软件包mysql

E: 无法定位软件包 mysql

在这里插入图片描述
修正安装命令:

sudo apt-get install mysql-server

在这里插入图片描述

关于安装完成后,部分关键信息的说明:

  1. mysql配置文件
    /etc/mysql/my.cnf (my.cnf)
  2. mysql错误日志路径
    /var/log/mysql/error.log
  3. 系统自动建立的软连接
    symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service
  4. 安装mysql的版本
    mysql-server (8.0.36-0ubuntu0.22.04.1)

配置MySQL账号密码

配置MySQL账号密码

sudo mysqladmin -u root -p password 'parish@1234'
mirror@mirror-Virtual-Machine:~$ sudo mysqladmin -u root -p password 'parish@1234'
Enter password: 
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.
mirror@mirror-Virtual-Machine:~$ 

用刚才建立的账号密码登录到MySQL

sudo mysqladmin -u root -p

在这里插入图片描述

配置MySQL的统一字符

通过对MySQL字符的配置,确保数据库服务器和客户端之间使用统一的字符集进行通信。

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
[client]
default-character-set=utf8
#  指定MySQL客户端连接到服务器时的默认字符集
[mysqld]
character-set-server=utf8
# 设置服务器端的默认字符集。
default-storage-engine=INNODB
# 定义MySQL在创建新表时,默认使用的存储引擎为InnoDB

default-character-set=utf8所有通过这个客户端连接的SQL查询和数据传输都会使用UTF-8字符集,确保在客户端与服务器交互过程中不会出现乱码问题,特别是处理非ASCII字符(例如中文、日文、韩文等多语言环境下的字符)。

character-set-server=utf8当创建新的数据库或表时,如果没有明确指定字符集,使用UTF-8作为默认字符编码。

启动MySQL服务

使用Systemd来启动MySQL服务

sudo systemctl start mysql.service

确保MySQL在系统启动时自动运行

sudo systemctl enable mysql.service

查看MySQL在当前的状态

sudo systemctl status mysql.service

在这里插入图片描述

允许远程连接

默认情况下,MySQL只监听本地接口(localhost)。如果你想允许来自局域网的访问,需要编辑MySQL的配置文件,找到 bind-address 行并修改它为你的服务器IP地址或0.0.0.0以监听所有接口。

编辑MySQL的配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

找到 bind-address 行

bind-address            = 127.0.0.1  # 修改为0.0.0.0或者指定的IP地址段

在这里插入图片描述
修改保存退出后,需要再次重启MySQL服务:

sudo systemctl restart mysql.service

Windows SSH连接Ubuntu

通过Windows安装的SSH工具,连接Ubuntu,注意Ubuntu需要安装ssh服务。

ssh mirror@172.18.54.116

在这里插入图片描述

以上就是MySQL数据在Ubuntu 22.04版本中安装的过程,希望对大家有所帮助。


推荐阅读

相关推荐

  1. ubuntu线安装mysql数据库

    2024-02-02 08:44:05       50 阅读
  2. MySQL商城数据表80-88

    2024-02-02 08:44:05       11 阅读
  3. MySQL商城数据表80-84

    2024-02-02 08:44:05       9 阅读
  4. MySQL 系列】 Ubuntu安装 MySQL

    2024-02-02 08:44:05       21 阅读
  5. ubuntu 18/20/22 安装 mysql 数据库

    2024-02-02 08:44:05       43 阅读
  6. Ubuntu20.04安装MySQL数据库

    2024-02-02 08:44:05       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-02 08:44:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-02 08:44:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-02 08:44:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-02 08:44:05       18 阅读

热门阅读

  1. Node.js EventEmitter详解

    2024-02-02 08:44:05       38 阅读
  2. spring boot bean的生命周期

    2024-02-02 08:44:05       24 阅读
  3. Flask 入门5 :过滤器

    2024-02-02 08:44:05       39 阅读
  4. docker-compose安装配置jenkins

    2024-02-02 08:44:05       28 阅读
  5. opencv——照片裁剪/照片斜的摆正

    2024-02-02 08:44:05       33 阅读
  6. Modern C++ idiom6 - 命名返回值优化NRVO

    2024-02-02 08:44:05       29 阅读
  7. 使用 Spring Boot 构建 Docker 镜像的简易指南

    2024-02-02 08:44:05       31 阅读
  8. MAC word删除空白页

    2024-02-02 08:44:05       31 阅读
  9. 【Shud】PIHMgis编译过程(上)编译GDAL详细步骤

    2024-02-02 08:44:05       31 阅读
  10. hot100:76数据流的中位数

    2024-02-02 08:44:05       36 阅读
  11. Iceberg从入门到精通系列之二十二:Spark DDL

    2024-02-02 08:44:05       25 阅读