如何在 ubuntu 22.04 上安装 mysql 5.7?

如何在 ubuntu 22.04 上安装 mysql 5.7?

我已经将服务器从 centos 升级到 ubuntu 22.04,但我想保留 mysql 5.7。

我使用 ansible 进行配置

默认情况下,ubuntu 22.04 apt 提供 mysql 8,所以我想我需要手动添加 repo、gpg 密钥环,然后才能安装。

但是我在这里没有看到 ubuntu 22.04 mysql 5,7 源https://dev.mysql.com/downloads/mysql/5.7.html?os=src

所以我想我需要一些非 ubuntu 特定的源:Linux - 通用(glibc 2.12)(x86, 32 位),也许还有 TAR?

我应该如何安装它,下面的代码不起作用,因为它不是 deb 包,需要从 tar.gz 中手动提取和安装,而且我不知道怎么做,我一直下载 html 而不是 tar.gz?

- name: Install Mysql GPG key
  become: true
  shell: "wget -qO - https://dev.mysql.com/downloads/gpg/?file=mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz&p=23 | gpg --dearmor -o /usr/share/keyrings/mysql-keyring.gpg"
  args:
    creates: "/usr/share/keyrings/mysql-keyring.gpg"

- name: Add Mysql deb repository
  shell: echo "deb [signed-by=/usr/share/keyrings/mysql-keyring.gpg] https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz stable main" | sudo tee /etc/apt/sources.list.d/mysql-5.7.39.list
  args:
    creates: "/etc/apt/sources.list.d/mysql-5.7.39.list"
  notify: reload apt

- name: Install MySQL Server
  apt:
    name: mysql-server
    state: present

- name: Start and enable MySQL
  systemd:
    name: mysql
    state: started
    enabled: yes

但这只是我的想法,可能有更好的方法,我唯一的目标是 ubuntu 22.04 上的 mysql 5.7

答案1

做好了!

---
- name: reload apt-get
  become: true
  shell: apt-get update

- name: Install Mysql GPG key
  become: true
  shell: "wget --no-check-certificate -qO - 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x859be8d7c586f538430b19c2467b942d3a79bd29' | gpg --dearmor -o /usr/share/keyrings/mysql-keyring.gpg"
  args:
    creates: "/usr/share/keyrings/mysql-keyring.gpg"
  notify: reload apt

- name: Add Mysql deb repository
  shell: echo "deb [signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7" | sudo tee /etc/apt/sources.list.d/mysql.list
  args:
    creates: "/etc/apt/sources.list.d/mysql.list"
  notify: reload apt

- name: install MySQL community client
  shell: apt install -fy mysql-community-client=5.7.39-1ubuntu18.04

- name: install MySQL client
  become: true
  shell: apt install -fy mysql-client=5.7.39-1ubuntu18.04

- name: Install MySQL Server
  apt:
    name: mysql-community-server
    state: present

- name: Start and enable MySQL
  systemd:
    name: mysql
    state: started
    enabled: yes

感谢 Ramhound 建议尝试 18.04 ubuntu 版本的 mysql

但此外我还必须手动安装依赖mysql-community-client项,mysql-client因为他们试图安装不兼容的 8.0 版本。

更新:

为了避免安装依赖项,您可以将版本固定到服务器,例如

- name: Install MySQL Server
  apt:
    name: mysql-community-server=5.7
    default_release: "bionic"
    state: present

答案2

如你看到的这里,Ubuntu 18.04 是 MySQL 5.7 版本支持的最后一个 Ubuntu 版本。

您可以尝试从源代码构建 MySQL 5.7你自己,不知道它是否可行并在 Ubuntu 22.04 上运行。

或者我建议运行通过 Docker 容器运行 MySQL 5.7。这无疑是最简单、最快捷的方法。

相关内容