Skip to content

Instantly share code, notes, and snippets.

@zhixingchou
Forked from fideloper/install_mysql.sh
Last active June 28, 2018 08:48
Show Gist options
  • Save zhixingchou/5987bd3271074a8981ff8408dfde1472 to your computer and use it in GitHub Desktop.
Save zhixingchou/5987bd3271074a8981ff8408dfde1472 to your computer and use it in GitHub Desktop.
instal mysql5.7 non-interactive on ubuntu 14.04
#!/usr/bin/env bash
# 安装mysql5.6版本
# * MySQL Community Server 5.6.40 is started
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment