Install thesql 5.7 on ubuntu 22.04

ansiblelinuxMySQLUbuntuwget

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

Best Answer

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