3

I have upgraded server from centos to ubuntu 22.04, but I want to keep mysql 5.7.

I use ansible for provisioning

By default ubuntu 22.04 apt gives mysql 8, so I think I need to add repo, gpg keyring manually and only then install.

However I don't see ubuntu 22.04 mysql 5,7 source here https://dev.mysql.com/downloads/mysql/5.7.html?os=src

So I guess I need some not ubuntu specific source: Linux - Generic (glibc 2.12) (x86, 32-bit), TAR maybe?

How I should install it, code below will not work because it's not deb package, it needs to be extracted and installed manually from tar.gz, and I don't know how, I keep getting html instead of tar.gz downloaded?

- 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

But it's just my thoughts, probably there's better way, my only goal is mysql 5.7 on ubuntu 22.04

3
  • 3
    Before you asked this question, did you try installing mysql-server_5.7.39-1ubuntu18.04_amd64.deb-bundle.tar, since that should still work?
    – Ramhound
    Commented Aug 12, 2022 at 17:58
  • no, will try it out Commented Aug 12, 2022 at 18:28
  • you were right, but I had to do a bunch of other things, will post an answer Commented Aug 16, 2022 at 20:10

2 Answers 2

3

Made it!

---
- 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

Thanks to Ramhound suggesting trying 18.04 ubuntu version of mysql

But in addition I had to manually install mysql-community-client and mysql-client dependencies because they tried to install incompatible 8.0 versions.

Update:

to avoid installing dependencies you can pin version to server like

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

As you can see here, Ubuntu 18.04 is the last Ubuntu version supported by MySQL for version 5.7.

You can try to build MySQL 5.7 from source yourself, whether that works and then runs on Ubuntu 22.04 I don't know.

Alternatively, I would recommend running MySQL 5.7 via Docker container. This is certainly the easiest and fastest way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .