Skip to content

Instantly share code, notes, and snippets.

@fideloper
Last active July 1, 2020 10:13
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fideloper/e774cb62d8be28da8a93 to your computer and use it in GitHub Desktop.
Save fideloper/e774cb62d8be28da8a93 to your computer and use it in GitHub Desktop.
instal mysql5.7 non-interactive on ubuntu 14.04
#!/usr/bin/env bash
# This is assumed to be run as root or with sudo
export DEBIAN_FRONTEND=noninteractive
# Import MySQL 5.7 Key
# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 5072E1F5
echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7" | tee -a /etc/apt/sources.list.d/mysql.list
apt-get update
# Install MySQL
MYSQL_PASS="secret"
debconf-set-selections <<< "mysql-community-server mysql-community-server/data-dir select ''"
debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password $MYSQL_PASS"
debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password $MYSQL_PASS"
apt-get install -y mysql-server
---
# Example tasks/main.yml file of a mysql ansible role, which should install mysql 5.7
# The apt_key id may need changing, I'm not sure
- name: Add MySQL Apt Key
apt_key:
keyserver: ha.pool.sks-keyservers.net
id: A4A9406876FCBD3C456770C88C718D3B5072E1F5
state: present
- name: Add MySQL Repository
copy:
src: mysql.list # This is files/mysql.list, which just contains "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7"
dest: /etc/apt/sources.list.d/mysql.list
owner: root
group: root
- name: Set root Password
debconf:
name: mysql-community-server
question: 'mysql-community-server/root-pass'
value: '{{ root_pass }}' # Set as a variable
vtype: password
- name: Set root Password Again
debconf:
name: mysql-community-server
question: 'mysql-community-server/re-root-pass'
value: '{{ root_pass }}' # Set as a variable
vtype: password
- name: Install MySQL 5.7
apt:
pkg: '{{ item }}'
state: latest
update_cache: true
with_items:
- mysql-server
notify:
- Start MySQL
@qstyler
Copy link

qstyler commented Aug 22, 2017

Hey! I have a question about this script.

When I'm running “apt-get update” after adding the source to the list I see this line in the output:
Hit http://repo.mysql.com trusty InRelease
and
Hit http://repo.mysql.com trusty/mysql-5.7 amd64 Packages

But when I do “apt-cache search mysql-server-5.7” i see nothing. And “apt-cache show mysql-server” it gives me version 5.5

What could've possibly went wrong during that script so I miss the 5.7 package?

@Protopopys
Copy link

Protopopys commented Jan 19, 2018

- name: Add Mysql apt key.
  apt_key:
    keyserver: ha.pool.sks-keyservers.net
    id: A4A9406876FCBD3C456770C88C718D3B5072E1F5
    state: present
  when: ansible_os_family == "Debian"
  tags:
    - mysql  

- name: Install a Mysql 5.7 REPO 
  apt_repository:
    repo={{ item }}
    state=present
  with_items:
    - "deb http://repo.mysql.com/apt/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} mysql-apt-config"
    - "deb http://repo.mysql.com/apt/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} mysql-5.7"
    - "deb http://repo.mysql.com/apt/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} mysql-tools"
    - "deb-src http://repo.mysql.com/apt/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} mysql-5.7"
  when: ansible_os_family == "Debian"
  tags:
    - mysql

- name: installing MySQL package via apt
  apt: 
    name={{ item }} 
    state=present
  with_items:
    - mysql-server 
  when: ansible_os_family == "Debian"
  tags:
    - mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment