├── README.md ├── scripts ├── show-help ├── start-client ├── start-server └── startup ├── snapcraft.yaml └── stage_binaries.sh /README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://www.mysql.com/common/logos/logo-mysql-170x115.png) 2 | 3 | # What is MySQL? 4 | 5 | MySQL is the world's most popular open source database. With its proven performance, reliability and ease-of-use, MySQL has become the leading database choice for web-based applications, covering the entire range from personal projects and websites, via online shops and information services, all the way to high profile web properties including Facebook, Twitter, YouTube, Yahoo! and many more. 6 | 7 | For more information and related downloads for MySQL Server and other MySQL products, please visit http://www.mysql.com. 8 | 9 | # MySQL Snap Image 10 | The MySQL snap image is an experimental release of MySQL for the snap universal Linux package system (http://snapcraft.io/). 11 | This image should be used for testing only, and is not suitable for a production environment. 12 | 13 | ## Commands 14 | - mysql.client: Runs the MySQL client 15 | - mysql.server: Runs the MySQL server 16 | - mysql.startup: Initializes database if necessary, then starts the server 17 | - mysql.help: Shows this document 18 | 19 | ## Usage guide 20 | The MySQL snap requires access to the process-control interface. You connect it by running: 21 | snap connect mysql:process-control core:process-control 22 | 23 | ### Running the snap 24 | * Install the snap as usual 25 | * Run sudo snap connect mysql:process-control ubuntu-core:process-control 26 | * Run mysql.startup to initialize and start the server 27 | * Run mysql.client -uroot -p 28 | 29 | ### Running the snap a system service 30 | Running MySQL as a system service requires root access, but the server itself should never run as root, so it drops privileges to a dedicated user. This user must own the server files and directories. Currently snapd blocks access to creating users and changing process user, so the only way to do this is to disable the restrictions by installing the snap with the --devmode argument. 31 | 32 | ### Files and directories 33 | The first time you run mysql.startup, it will generate the following in $HOME/snap/mysql/common (if run as root, /var/snap/mysql/common is used instead): 34 | - conf/my.cnf: Basic configuration file 35 | - data/: Data directoriy 36 | - files/: Default location for the secure-file-priv option 37 | - log/: Location of error log 38 | - run/: Location of sock and pid files 39 | -------------------------------------------------------------------------------- /scripts/show-help: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; version 2 of the License. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | 18 | cat << EOF 19 | 20 | = MySQL Snap Image = 21 | The MySQL snap image is an experimental release of MySQL for the snap universal Linux package system (http://snapcraft.io/). 22 | This image should be used for testing only, and is not suitable for a production environment. 23 | 24 | == Commands == 25 | - mysql.client: Runs the MySQL client 26 | - mysql.server: Runs the MySQL server 27 | - mysql.startup: Initializes database if necessary, then starts the server 28 | - mysql.help: Shows this document 29 | 30 | == Usage guide == 31 | The MySQL snap requires access to the process-control interface. You connect it by running: 32 | snap connect mysql:process-control core:process-control 33 | 34 | === Running the snap === 35 | * Install the snap as usual 36 | * Run sudo snap connect mysql:process-control ubuntu-core:process-control 37 | * Run mysql.startup to initialize and start the server 38 | * Run mysql.client -uroot -p 39 | 40 | === Running the snap a system service === 41 | Running MySQL as a system service requires root access, but the server itself should never run as root, so it drops privileges to a dedicated user. This user must own the server files and directories. Currently snapd blocks access to creating users and changing process user, so the only way to do this is to disable the restrictions by installing the snap with the --devmode argument. 42 | 43 | === Files and directories === 44 | The first time you run mysql.startup, it will generate the following in $HOME/snap/mysql/common (if run as root, /var/snap/mysql/common is used instead): 45 | - conf/my.cnf: Basic configuration file 46 | - data/: Data directoriy 47 | - files/: Default location for the secure-file-priv option 48 | - log/: Location of error log 49 | - run/: Location of sock and pid files 50 | EOF 51 | -------------------------------------------------------------------------------- /scripts/start-client: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; version 2 of the License. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | if [ -f "${SNAP_USER_COMMON}/conf/my.cnf" ]; 18 | then 19 | MYSQL_CONFFILE="${SNAP_USER_COMMON}/conf/my.cnf" 20 | elif [ -f "${SNAP_COMMON}/conf/my.cnf" ]; 21 | then 22 | MYSQL_CONFFILE="${SNAP_COMMON}/conf/my.cnf" 23 | else 24 | echo "WARNING: Can't find config file. Did you run mysql.startup?" 25 | fi 26 | 27 | if [ -f ${MYSQL_CONFFILE} ]; 28 | then 29 | echo "Using config file: ${MYSQL_CONFFILE}" 30 | MYSQL_CONFPARAM="--defaults-file=${MYSQL_CONFFILE}" 31 | fi 32 | mysql "${MYSQL_CONFPARAM}" $@ 33 | -------------------------------------------------------------------------------- /scripts/start-server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; version 2 of the License. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | USERID=$(id -u) 18 | if [ "${USERID}" = "0" ]; 19 | then 20 | MYSQL_SNAPDIR=${SNAP_COMMON} 21 | VARS="--user=mysql" 22 | else 23 | MYSQL_SNAPDIR=${SNAP_USER_COMMON} 24 | VARS="" 25 | fi 26 | 27 | echo "Starting server..." 28 | mysqld --defaults-file="${MYSQL_SNAPDIR}/conf/my.cnf" ${VARS} $@ 29 | -------------------------------------------------------------------------------- /scripts/startup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; version 2 of the License. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | set -e 18 | init_config() { 19 | mkdir "${CONFDIR}" 20 | echo "Generating config file in ${CONFFILE}..." 21 | touch "${CONFFILE}" 22 | echo "[mysqld]" >> ${CONFFILE} 23 | echo "pid-file=${RUNDIR}/mysqld.pid" >> ${CONFFILE} 24 | echo "socket=${RUNDIR}/mysqld.sock" >> ${CONFFILE} 25 | echo "datadir=${DATADIR}" >> ${CONFFILE} 26 | echo "log-error=${LOGDIR}/error.log" >> ${CONFFILE} 27 | echo "secure-file-priv=${FILESDIR}" >> ${CONFFILE} 28 | echo "basedir=${BASEDIR}" >> ${CONFFILE} 29 | echo "[mysql]" >> ${CONFFILE} 30 | echo "socket=${RUNDIR}/mysqld.sock" >> ${CONFFILE} 31 | echo "Done" 32 | } 33 | 34 | init_database() { 35 | echo "Initializing new database in ${DATADIR}..." 36 | mkdir "${DATADIR}" 37 | mysqld --defaults-file="${CONFFILE}" --initialize 38 | echo "Done" 39 | cat ${LOGDIR}/error.log | grep "temporary password" 40 | } 41 | 42 | USERID=$(id -u) 43 | if [ "${USERID}" = "0" ];then 44 | MYSQL_SNAPDIR="${SNAP_COMMON}" 45 | else 46 | MYSQL_SNAPDIR="${SNAP_USER_COMMON}" 47 | fi 48 | DATADIR="${MYSQL_SNAPDIR}/data" 49 | RUNDIR="${MYSQL_SNAPDIR}/run" 50 | LOGDIR="${MYSQL_SNAPDIR}/log" 51 | CONFDIR="${MYSQL_SNAPDIR}/conf" 52 | CONFFILE="${CONFDIR}/my.cnf" 53 | FILESDIR="${MYSQL_SNAPDIR}/files" 54 | BASEDIR="${SNAP}/usr" 55 | 56 | [ -d "${LOGDIR}" ] || mkdir "${LOGDIR}" 57 | [ -f "${LOGDIR}/error.log" ] || touch "${LOGDIR}/error.log" 58 | [ -d "${FILESDIR}" ] || mkdir "${FILESDIR}" 59 | [ -d "${RUNDIR}" ] || mkdir "${RUNDIR}" 60 | [ -d "${CONFDIR}" ] || init_config 61 | [ -d "${DATADIR}" ] || init_database 62 | 63 | if [ "${USERID}" = "0" ]; 64 | then 65 | # Ensure mysql user exists and that the correct permissions are set on various directories 66 | adduser --system --disabled-login --ingroup mysql --home /nonexistent --gecos "MySQL Server" --shell /bin/false mysql >/dev/null 67 | chown -R mysql:mysql "${LOGDIR}" "${FILESDIR}" "${DATADIR}" "${RUNDIR}" 68 | chmod 750 "${LOGDIR}" "${DATADIR}" 69 | chmod 770 "${FILESDIR}" 70 | chmod 755 "${RUNDIR}" 71 | VARS="--user=mysql" 72 | fi 73 | echo "Starting server..." 74 | mysqld --defaults-file="${CONFFILE}" ${VARS} $@ 75 | 76 | -------------------------------------------------------------------------------- /snapcraft.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; version 2 of the License. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with this program; if not, write to the Free Software 14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | 16 | name: mysql 17 | version: "5.7.17" 18 | summary: MySQL Community snap 19 | description: MySQL Snap 20 | Contains the minimal set of binaries needed for the MySQL server and client. 21 | This is meant as a way to try out MySQL with Snappy, and is not to be 22 | considered ready for production environments. 23 | Before running, the process control interface must be connected with the command 24 | snap connect mysql-experimental:process-control core:process-control 25 | confinement: strict 26 | grade: devel 27 | 28 | apps: 29 | startup: 30 | command: startup 31 | plugs: 32 | - process-control 33 | - network 34 | - network-bind 35 | server: 36 | command: start-server 37 | plugs: 38 | - process-control 39 | - network 40 | - network-bind 41 | client: 42 | command: start-client 43 | plugs: 44 | - process-control 45 | - network 46 | - network-bind 47 | help: 48 | command: show-help 49 | 50 | parts: 51 | mysql-server: 52 | prepare: ./stage_binaries.sh 53 | build-packages: [libaio-dev, libmecab-dev, libnuma-dev, libncurses5-dev, wget, zlib1g-dev] 54 | plugin: dump 55 | source: ./ 56 | organize: 57 | staging-files/usr: usr/ 58 | snap: 59 | - usr/lib/mysql/plugin/mysql_no_login.so 60 | - usr/lib/mysql/plugin/innodb_engine.so 61 | - usr/lib/mysql/plugin/mypluglib.so 62 | - usr/lib/mysql/plugin/locking_service.so 63 | - usr/lib/mysql/plugin/adt_null.so 64 | - usr/lib/mysql/plugin/rewriter.so 65 | - usr/lib/mysql/plugin/keyring_udf.so 66 | - usr/lib/mysql/plugin/libmemcached.so 67 | - usr/lib/mysql/plugin/auth_socket.so 68 | - usr/lib/mysql/plugin/validate_password.so 69 | - usr/lib/mysql/plugin/semisync_slave.so 70 | - usr/lib/mysql/plugin/semisync_master.so 71 | - usr/lib/mysql/plugin/keyring_file.so 72 | - usr/lib/mysql/plugin/mysqlx.so 73 | - usr/lib/mysql/plugin/version_token.so 74 | - usr/lib/mysql/plugin/libpluginmecab.so 75 | - usr/lib/mysql/plugin/group_replication.so 76 | - usr/sbin/mysqld 77 | - usr/bin/mysqlpump 78 | - usr/bin/mysql 79 | - usr/bin/mysql_ssl_rsa_setup 80 | - usr/bin/my_print_defaults 81 | - usr/bin/mysqldump 82 | - usr/bin/mysql_tzinfo_to_sql 83 | - usr/bin/mysql_upgrade 84 | - usr/share/mysql/* 85 | scripts: 86 | plugin: dump 87 | source: ./scripts 88 | organize: 89 | show-help: bin/show-help 90 | start-server: bin/start-server 91 | start-client: bin/start-client 92 | startup: bin/startup 93 | -------------------------------------------------------------------------------- /stage_binaries.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; version 2 of the License. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | 17 | SNAPDIR=$(pwd) 18 | SNAPTMP=$(mktemp -d) 19 | cd ${SNAPTMP} 20 | MYSQL_VERSION_MAJOR=5.7 21 | MYSQL_VERSION_FULL=5.7.17-1ubuntu16.04 22 | FILENAME="mysql-server_${MYSQL_VERSION_FULL}_amd64.deb-bundle.tar" 23 | wget "http://dev.mysql.com/get/Downloads/MySQL-{MYSQL_VERSION_MAJOR}/${FILENAME}" 24 | tar -xvf "${FILENAME}" 25 | ar x mysql-community-client_${MYSQL_VERSION_FULL}_amd64.deb 26 | tar -xvf data.tar.xz 27 | rm data.tar.xz 28 | ar x mysql-community-server_${MYSQL_VERSION_FULL}_amd64.deb 29 | tar -xvf data.tar.xz 30 | mkdir staging-files 31 | mv usr staging-files/ 32 | rm -rf ${SNAPDIR}/staging-files 33 | mv staging-files ${SNAPDIR} 34 | cd ${SNAPDIR} 35 | --------------------------------------------------------------------------------