diff options
Diffstat (limited to 'scripts')
26 files changed, 2739 insertions, 2372 deletions
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 79d87fcf6be..13fc69912f6 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -79,6 +79,8 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mysql_performance_tables.sql ${CMAKE_CURRENT_SOURCE_DIR}/fill_help_tables.sql ${CMAKE_CURRENT_SOURCE_DIR}/mysql_test_data_timezone.sql + ${CMAKE_CURRENT_SOURCE_DIR}/maria_add_gis_sp.sql + ${CMAKE_CURRENT_SOURCE_DIR}/maria_add_gis_sp_bootstrap.sql ${FIX_PRIVILEGES_SQL} DESTINATION ${INSTALL_MYSQLSHAREDIR} COMPONENT Server ) @@ -89,7 +91,7 @@ IF(MALLOC_LIB) INSTALL(FILES ${MALLOC_LIB} DESTINATION ${INSTALL_LIBDIR} OPTIONAL) ENDIF() -IF(CMAKE_GENERATOR MATCHES "Makefiles") +IF(CMAKE_GENERATOR MATCHES "Makefiles|Ninja") FOREACH(ARCH ${CMAKE_OSX_ARCHITECTURES}) SET(CFLAGS "${CFLAGS} -arch ${ARCH}") SET(CXXFLAGS "${CXXFLAGS} -arch ${ARCH}") @@ -237,57 +239,6 @@ ELSE() SET(TARGET_LINUX "false") ENDIF() -# Use cmake variables to inspect dependencies for -# mysqlclient library (add -l stuff) -SET(CLIENT_LIBS "") -SET(LIBS "") - -# Avoid compatibility warning about lists with empty elements -IF(POLICY CMP0011) - CMAKE_POLICY(SET CMP0011 NEW) -ENDIF() -IF(POLICY CMP0007) - CMAKE_POLICY(SET CMP0007 OLD) -ENDIF() - -# Extract dependencies using CMake's internal ${target}_LIB_DEPENDS variable -# returned string in ${var} is can be passed to linker's command line -MACRO(EXTRACT_LINK_LIBRARIES target var) - IF(${target}_LIB_DEPENDS) - LIST(REMOVE_ITEM ${target}_LIB_DEPENDS "") - LIST(REMOVE_DUPLICATES ${target}_LIB_DEPENDS) - FOREACH(lib ${${target}_LIB_DEPENDS}) - # Filter out "general", it is not a library, just CMake hint - # Also, remove duplicates - IF(NOT lib STREQUAL "general" AND NOT ${var} MATCHES "-l${lib} ") - IF (lib MATCHES "^\\-l") - SET(${var} "${${var}} ${lib} ") - ELSEIF(lib MATCHES "^/") - IF (lib MATCHES "\\.(a|so([0-9.]*)|lib|dll|dylib)$") - # Full path, convert to just filename, strip "lib" prefix and extension - GET_FILENAME_COMPONENT(lib "${lib}" NAME_WE) - STRING(REGEX REPLACE "^lib" "" lib "${lib}") - SET(${var} "${${var}}-l${lib} " ) - ENDIF() - ELSE() - SET(${var} "${${var}}-l${lib} " ) - ENDIF() - ENDIF() - ENDFOREACH() - ENDIF() - IF(MSVC) - STRING(REPLACE "-l" "" ${var} "${${var}}") - ENDIF() -ENDMACRO() - -EXTRACT_LINK_LIBRARIES(mysqlclient CLIENT_LIBS) -EXTRACT_LINK_LIBRARIES(mysqlserver LIBS) - -# mysql_config evaluates ${LIBDL}, we want to avoid it -# as our CLIENT_LIBS and LIBS are already correct -SET(LIBDL) - -SET(NON_THREADED_LIBS ${CLIENT_LIBS}) SET(mysql_config_COMPONENT COMPONENT Development) SET(msql2mysql_COMPONENT COMPONENT Client) SET(mysqlaccess_COMPONENT COMPONENT Client) @@ -320,6 +271,15 @@ IF(WIN32) INSTALL_SCRIPT(${CMAKE_CURRENT_BINARY_DIR}/${file}.pl COMPONENT Server_Scripts) ENDFOREACH() ELSE() + IF(WITH_WSREP) + SET(WSREP_BINARIES + wsrep_sst_common + wsrep_sst_mysqldump + wsrep_sst_rsync + wsrep_sst_xtrabackup + wsrep_sst_xtrabackup-v2 + ) + ENDIF() # Configure this one, for testing, but do not install it. CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql_config.pl.in ${CMAKE_CURRENT_BINARY_DIR}/mysql_config.pl ESCAPE_QUOTES @ONLY) @@ -339,6 +299,7 @@ ELSE() mysqldumpslow mysqld_multi mysqld_safe + ${WSREP_BINARIES} ) FOREACH(file ${BIN_SCRIPTS}) IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh) diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh deleted file mode 100644 index 663686ac1c8..00000000000 --- a/scripts/make_binary_distribution.sh +++ /dev/null @@ -1,386 +0,0 @@ -#!/bin/sh -# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -############################################################################## -# -# This is a script to create a TAR or ZIP binary distribution out of a -# built source tree. The output file will be put at the top level of -# the source tree, as "mysql-<vsn>....{tar.gz,zip}" -# -# Note that the structure created by this script is slightly different from -# what a normal "make install" would produce. No extra "mysql" sub directory -# will be created, i.e. no "$prefix/include/mysql", "$prefix/lib/mysql" or -# "$prefix/share/mysql". This is because the build system explicitly calls -# make with pkgdatadir=<datadir>, etc. -# -# In GNU make/automake terms -# -# "pkglibdir" is set to the same as "libdir" -# "pkgincludedir" is set to the same as "includedir" -# "pkgdatadir" is set to the same as "datadir" -# "pkgplugindir" is set to "$pkglibdir/plugin" -# "pkgsuppdir" is set to "@prefix@/support-files", -# normally the same as "datadir" -# -# The temporary directory path given to "--tmp=<path>" has to be -# absolute and with no spaces. -# -# Note that for best result, the original "make" should be done with -# the same arguments as used for "make install" below, especially the -# 'pkglibdir', as the RPATH should to be set correctly. -# -############################################################################## - -############################################################################## -# -# Read the command line arguments that control this script -# -############################################################################## - -machine=@MACHINE_TYPE@ -system=@SYSTEM_TYPE@ -SOURCE=`pwd` -CP="cp -p" -MV="mv" - -# There are platforms, notably OS X on Intel (x86 + x86_64), -# for which "uname" does not provide sufficient information. -# The value of CFLAGS as used during compilation is the most exact info -# we can get - after all, we care about _what_ we built, not _where_ we did it. -cflags="@CFLAGS@" - -STRIP=1 # Option ignored -SILENT=0 -MALLOC_LIB= -PLATFORM="" -TMP=/tmp -NEW_NAME="" # Final top directory and TAR package name -SUFFIX="" -SHORT_PRODUCT_TAG="" # If don't want server suffix in package name -NDBCLUSTER="" # Option ignored - -for arg do - case "$arg" in - --tmp=*) TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;; - --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;; - --short-product-tag=*) SHORT_PRODUCT_TAG=`echo "$arg" | sed -e "s;--short-product-tag=;;"` ;; - --inject-malloc-lib=*) MALLOC_LIB=`echo "$arg" | sed -e 's;^[^=]*=;;'` ;; - --no-strip) STRIP=0 ;; - --machine=*) machine=`echo "$arg" | sed -e "s;--machine=;;"` ;; - --platform=*) PLATFORM=`echo "$arg" | sed -e "s;--platform=;;"` ;; - --silent) SILENT=1 ;; - --with-ndbcluster) NDBCLUSTER=1 ;; - *) - echo "Unknown argument '$arg'" - exit 1 - ;; - esac -done - -# ---------------------------------------------------------------------- -# Adjust "system" output from "uname" to be more human readable -# ---------------------------------------------------------------------- - -if [ x"$PLATFORM" = x"" ] ; then - # FIXME move this to the build tools - # Remove vendor from $system - system=`echo $system | sed -e 's/[a-z]*-\(.*\)/\1/g'` - - # Map OS names to "our" OS names (eg. darwin6.8 -> osx10.2) - system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'` - system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'` - system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'` - system=`echo $system | sed -e 's/darwin9.*/osx10.5/g'` - system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'` - system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'` - system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'` - system=`echo $system | sed -e 's/\(aix5.3\).*/\1/g'` - system=`echo $system | sed -e 's/osf5.1b/tru64/g'` - system=`echo $system | sed -e 's/linux-gnu/linux/g'` - system=`echo $system | sed -e 's/solaris2.\([0-9]*\)/solaris\1/g'` - system=`echo $system | sed -e 's/sco3.2v\(.*\)/openserver\1/g'` -fi - -# Get the "machine", which really is the CPU architecture (including the size). -# The precedence is: -# 1) use an explicit argument, if given; -# 2) use platform-specific fixes, if there are any (see bug#37808); -# 3) stay with the default (determined during "configure", using predefined macros). - -if [ x"$MACHINE" != x"" ] ; then - machine=$MACHINE -else - case $system in - osx* ) - # Extract "XYZ" from CFLAGS "... -arch XYZ ...", or empty! - cflag_arch=`echo "$cflags" | sed -n -e 's=.* -arch \([^ ]*\) .*=\1=p'` - case "$cflag_arch" in - i386 ) case $system in - osx10.4 ) machine=i686 ;; # Used a different naming - * ) machine=x86 ;; - esac ;; - x86_64 ) machine=x86_64 ;; - ppc ) ;; # No treatment needed with PPC - ppc64 ) ;; - * ) # No matching compiler flag? "--platform" is needed - if [ x"$PLATFORM" != x"" ] ; then - : # See below: "$PLATFORM" will take precedence anyway - elif [ "$system" = "osx10.3" -a -z "$cflag_arch" ] ; then - : # Special case of OS X 10.3, which is PPC-32 only and doesn't use "-arch" - else - echo "On system '$system' only specific '-arch' values are expected." - echo "It is taken from the 'CFLAGS' whose value is:" - echo "$cflags" - echo "'-arch $cflag_arch' is unexpected, and no '--platform' was given: ABORT" - exit 1 - fi ;; - esac # "$cflag_arch" - ;; - esac # $system -fi - -# Combine OS and CPU to the "platform". Again, an explicit argument takes precedence. -if [ x"$PLATFORM" != x"" ] ; then - : -else - PLATFORM="$system-$machine" -fi - -# Print the platform name for build logs -echo "PLATFORM NAME: $PLATFORM" - -# Change the distribution to a long descriptive name -# For the cluster product, concentrate on the second part -VERSION_NAME=@VERSION@ -case $VERSION_NAME in - *-ndb-* ) VERSION_NAME=`echo $VERSION_NAME | sed -e 's/[.0-9]*-ndb-//'` ;; - *-MariaDB-* ) VERSION_NAME=`echo $VERSION_NAME | sed -e 's/-MariaDB//'` ;; -esac -if [ x"$SHORT_PRODUCT_TAG" != x"" ] ; then - NEW_NAME=mariadb-$SHORT_PRODUCT_TAG-$VERSION_NAME-$PLATFORM$SUFFIX -else - NEW_NAME=mariadb@MYSQL_SERVER_SUFFIX@-$VERSION_NAME-$PLATFORM$SUFFIX -fi - -# ---------------------------------------------------------------------- -# Define BASE, and remove the old BASE directory if any -# ---------------------------------------------------------------------- -BASE=$TMP/my_dist$SUFFIX -if [ -d $BASE ] ; then - rm -rf $BASE -fi - -# ---------------------------------------------------------------------- -# Find the TAR to use -# ---------------------------------------------------------------------- - -# This is needed to prefer GNU tar over platform tar because that can't -# always handle long filenames - -PATH_DIRS=`echo $PATH | \ - sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' ` - -which_1 () -{ - for cmd - do - for d in $PATH_DIRS - do - for file in $d/$cmd - do - if [ -x $file -a ! -d $file ] ; then - echo $file - exit 0 - fi - done - done - done - exit 1 -} - -tar=`which_1 gnutar gtar` -if [ $? -ne 0 -o x"$tar" = x"" ] ; then - tar=tar -fi - - -############################################################################## -# -# Handle the Unix/Linux packaging using "make install" -# -############################################################################## - -# ---------------------------------------------------------------------- -# Terminate on any base level error -# ---------------------------------------------------------------------- -set -e - -# -# Check that the client is compiled with libmysqlclient.a -# -if test -f ./client/.libs/mysql -then - echo "" - echo "The MySQL clients are compiled dynamicly, which is not allowed for" - echo "a MySQL binary tar file. Please configure with" - echo "--with-client-ldflags=-all-static and try again" - exit 1; -fi - -# ---------------------------------------------------------------------- -# Really ugly, one script, "mysql_install_db", needs prefix set to ".", -# i.e. makes access relative the current directory. This matches -# the documentation, so better not change this. And for another script, -# "mysql.server", we make some relative, others not. -# ---------------------------------------------------------------------- - -cd scripts -rm -f mysql_install_db mysqld_safe mysql_fix_privilege_tables -@MAKE@ mysql_install_db mysqld_safe mysql_fix_privilege_tables \ - prefix=. \ - bindir=./bin \ - sbindir=./bin \ - scriptdir=./bin \ - libexecdir=./bin \ - pkgdatadir=./share \ - localstatedir=./data -cd .. - -cd support-files -rm -f mysql.server -@MAKE@ mysql.server \ - bindir=./bin \ - sbindir=./bin \ - scriptdir=./bin \ - libexecdir=./bin \ - pkgdatadir=./share -cd .. - -# ---------------------------------------------------------------------- -# Do a install that we later are to pack. Use the same paths as in -# the build for the relevant directories. -# ---------------------------------------------------------------------- -@MAKE@ DESTDIR=$BASE install \ - libexecdir=@prefix@/libexec \ - pkglibdir=@pkglibdir@ \ - pkgincludedir=@pkgincludedir@ \ - pkgdatadir=@pkgdatadir@ \ - pkgplugindir=@pkgplugindir@ \ - pkgsuppdir=@pkgsuppdir@ \ - mandir=@mandir@ \ - infodir=@infodir@ - -# ---------------------------------------------------------------------- -# Rename top directory, and set DEST to the new directory -# ---------------------------------------------------------------------- -mv $BASE@prefix@ $BASE/$NEW_NAME -DEST=$BASE/$NEW_NAME - -# ---------------------------------------------------------------------- -# If we compiled with gcc, copy libgcc.a to the dist as libmygcc.a -# ---------------------------------------------------------------------- -if [ x"@GXX@" = x"yes" ] ; then - gcclib=`@CC@ @CFLAGS@ --print-libgcc-file 2>/dev/null` || true - if [ -z "$gcclib" ] ; then - echo "Warning: Compiler doesn't tell libgcc.a!" - elif [ -f "$gcclib" ] ; then - $CP $gcclib $DEST/lib/libmygcc.a - else - echo "Warning: Compiler result '$gcclib' not found / no file!" - fi -fi - -# If requested, add a malloc library .so into pkglibdir for use -# by mysqld_safe -if [ -n "$MALLOC_LIB" ]; then - cp "$MALLOC_LIB" "$DEST/lib/" -fi - -# Note, no legacy "safe_mysqld" link to "mysqld_safe" in 5.1 - -# Copy readme and license files -cp README Docs/INSTALL-BINARY TODO CREDITS $DEST/ -if [ -f COPYING -a -f EXCEPTIONS-CLIENT ] ; then - cp COPYING EXCEPTIONS-CLIENT $DEST/ -elif [ -f LICENSE.mysql ] ; then - cp LICENSE.mysql $DEST/ -else - echo "ERROR: no license files found" - exit 1 -fi - -# FIXME should be handled by make file, and to other dir -mkdir -p $DEST/bin $DEST/support-files -cp scripts/mysqlaccess.conf $DEST/bin/ -cp support-files/magic $DEST/support-files/ - -# Create empty data directories, set permission (FIXME why?) -mkdir $DEST/data $DEST/data/mysql $DEST/data/test -chmod o-rwx $DEST/data $DEST/data/mysql $DEST/data/test - -# Remove not needed files -rm $DEST/share/mysql/errmsg.txt - -# Remove NDB files -rm -f $DEST/share/mysql/ndb-config-2-node.ini \ - $DEST/share/mysql/config* - -# -# Move things to make them easier to find in tar installation -# - -# The following test is needed if the original configure was done with -# something like --libexecdir=/usr/local/mysql/bin -if test -f $DEST/libexec/mysqld -then - mv $DEST/libexec/* $DEST/bin - rmdir $DEST/libexec -fi -mv $DEST/share/man $DEST -mv $DEST/share/mysql/binary-configure $DEST/configure -mv $DEST/share/mysql/*.sql $DEST/share -mv $DEST/share/mysql/*.cnf $DEST/share/mysql/*.server $DEST/share/mysql/mysql-log-rotate $DEST/support-files - -# -# Move some scripts that are only run once to 'scripts' directory -# but add symbolic links instead to old place for compatibility -# -mkdir $DEST/scripts -for i in mysql_secure_installation mysql_fix_extensions mysql_fix_privilege_tables mysql_install_db mytop -do - mv $DEST/bin/$i $DEST/scripts - ln -s "../scripts/$i" $DEST/bin/$i -done - -# ---------------------------------------------------------------------- -# Create the result tar file -# ---------------------------------------------------------------------- - -echo "Using $tar to create archive" -OPT=cvf -if [ x$SILENT = x1 ] ; then - OPT=cf -fi - -echo "Creating and compressing archive" -rm -f $NEW_NAME.tar.gz -(cd $BASE ; $tar $OPT - $NEW_NAME) | gzip -9 > $NEW_NAME.tar.gz -echo "$NEW_NAME.tar.gz created" - -echo "Removing temporary directory" -rm -rf $BASE -exit 0 - diff --git a/scripts/maria_add_gis_sp.sql b/scripts/maria_add_gis_sp.sql new file mode 100644 index 00000000000..8ddc7abd17f --- /dev/null +++ b/scripts/maria_add_gis_sp.sql @@ -0,0 +1,48 @@ +-- Copyright (C) 2014 MariaDB Ab. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; version 2 of the License. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +-- This part creates stored procedures required by the OpenGIS standards. +-- Proc privilege is needed to run it. +-- To use this file, load its contents into the mysql database like that: +-- mysql -u root -p mysql < scripts/maria_add_gis_sp.sql + +SET sql_mode=''; + +DROP PROCEDURE IF EXISTS AddGeometryColumn; +DROP PROCEDURE IF EXISTS DropGeometryColumn; + +delimiter | + +CREATE PROCEDURE AddGeometryColumn(catalog varchar(64), t_schema varchar(64), + t_name varchar(64), geometry_column varchar(64), t_srid int) +begin + set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); + PREPARE ls from @qwe; + execute ls; + deallocate prepare ls; +end| + +CREATE PROCEDURE DropGeometryColumn(catalog varchar(64), t_schema varchar(64), + t_name varchar(64), geometry_column varchar(64)) +begin + set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); + PREPARE ls from @qwe; + execute ls; + deallocate prepare ls; +end| + +delimiter ; + diff --git a/scripts/maria_add_gis_sp_bootstrap.sql b/scripts/maria_add_gis_sp_bootstrap.sql new file mode 100644 index 00000000000..063b6650efd --- /dev/null +++ b/scripts/maria_add_gis_sp_bootstrap.sql @@ -0,0 +1,34 @@ +-- Copyright (C) 2014 MariaDB Ab. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; version 2 of the License. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +# This part creates stored procedures required by the OpenGIS standards. +# script is prepared to be run with the --bootstrap server option + +SET sql_mode=''; + +DROP PROCEDURE IF EXISTS AddGeometryColumn; +DROP PROCEDURE IF EXISTS DropGeometryColumn; + +CREATE PROCEDURE AddGeometryColumn(catalog varchar(64), t_schema varchar(64), + t_name varchar(64), geometry_column varchar(64), t_srid int) +begin + set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end; + +CREATE PROCEDURE DropGeometryColumn(catalog varchar(64), t_schema varchar(64), + t_name varchar(64), geometry_column varchar(64)) +begin + set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end; + + diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh index 47010ac087b..52f6d563fe5 100644 --- a/scripts/mysql_config.sh +++ b/scripts/mysql_config.sh @@ -15,7 +15,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # This script reports various configuration settings that may be needed -# when using the MySQL client library. +# when using the MariaDB client library. which () { @@ -39,7 +39,7 @@ which () # # If we can find the given directory relatively to where mysql_config is # we should use this instead of the incompiled one. -# This is to ensure that this script also works with the binary MySQL +# This is to ensure that this script also works with the binary MariaDB # version fix_path () @@ -97,7 +97,6 @@ fix_path pkgincludedir include/mysql version='@VERSION@' socket='@MYSQL_UNIX_ADDR@' -ldflags='@LDFLAGS@' if [ @MYSQL_TCP_PORT_DEFAULT@ -eq 0 ]; then port=0 @@ -106,58 +105,14 @@ else fi # Create options -# We intentionally add a space to the beginning and end of lib strings, simplifies replace later -libs=" $ldflags -L$pkglibdir @RPATH_OPTION@ -lmysqlclient @ZLIB_DEPS@ @NON_THREADED_LIBS@" -libs="$libs @openssl_libs@ @STATIC_NSS_FLAGS@ " -libs_r=" $ldflags -L$pkglibdir @RPATH_OPTION@ -lmysqlclient_r @ZLIB_DEPS@ @CLIENT_LIBS@ @openssl_libs@ " -embedded_libs=" $ldflags -L$pkglibdir @RPATH_OPTION@ -lmysqld @LIBDL@ @ZLIB_DEPS@ @LIBS@ @WRAPLIBS@ @openssl_libs@ " - -if [ -r "$pkglibdir/libmygcc.a" ]; then - # When linking against the static library with a different version of GCC - # from what was used to compile the library, some symbols may not be defined - # automatically. We package the libmygcc.a from the build host, to provide - # definitions for those. Bugs 4921, 19561, 19817, 21158, etc. - libs="$libs -lmygcc " - libs_r="$libs_r -lmygcc " - embedded_libs="$embedded_libs -lmygcc " -fi +libs="-L$pkglibdir @RPATH_OPTION@ @LIBS_FOR_CLIENTS@" +embedded_libs="-L$pkglibdir @RPATH_OPTION@ @EMB_LIBS_FOR_CLIENTS@" include="-I$pkgincludedir" if [ "$basedir" != "/usr" ]; then include="$include -I$pkgincludedir/.." fi -cflags="$include @CFLAGS@ " #note: end space! - -# Remove some options that a client doesn't have to care about -# FIXME until we have a --cxxflags, we need to remove -Xa -# and -xstrconst to make --cflags usable for Sun Forte C++ -# FIXME until we have a --cxxflags, we need to remove -AC99 -# to make --cflags usable for HP C++ (aCC) -for remove in DDBUG_OFF DSAFE_MUTEX DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS \ - DEXTRA_DEBUG DHAVE_valgrind O 'O[0-9]' 'xO[0-9]' 'W[-A-Za-z]*' \ - 'mtune=[-A-Za-z0-9]*' 'mcpu=[-A-Za-z0-9]*' 'march=[-A-Za-z0-9]*' \ - Xa xstrconst "xc99=none" AC99 'W[-A-Za-z]*=[-A-Za-z0-9]*' \ - unroll2 ip mp restrict -do - # The first option we might strip will always have a space before it because - # we set -I$pkgincludedir as the first option - cflags=`echo "$cflags"|sed -e ':again' -e "s/ -$remove */ /g" -e 't again'` -done -cflags=`echo "$cflags"|sed -e 's/ *\$//'` - -# Same for --libs(_r) -for remove in lmtmalloc static-libcxa i-static static-intel -do - # We know the strings starts with a space - libs=`echo "$libs"|sed -e "s/ -$remove */ /g"` - libs_r=`echo "$libs_r"|sed -e "s/ -$remove */ /g"` - embedded_libs=`echo "$embedded_libs"|sed -e "s/ -$remove */ /g"` -done - -# Strip trailing and ending space if any, and '+' (FIXME why?) -libs=`echo "$libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'` -libs_r=`echo "$libs_r" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'` -embedded_libs=`echo "$embedded_libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'` +cflags="$include @CFLAGS_FOR_CLIENTS@" usage () { cat <<EOF @@ -166,7 +121,7 @@ Options: --cflags [$cflags] --include [$include] --libs [$libs] - --libs_r [$libs_r] + --libs_r [$libs] --plugindir [$plugindir] --socket [$socket] --port [$port] @@ -187,7 +142,7 @@ while test $# -gt 0; do --cflags) echo "$cflags" ;; --include) echo "$include" ;; --libs) echo "$libs" ;; - --libs_r) echo "$libs_r" ;; + --libs_r) echo "$libs" ;; --plugindir) echo "$plugindir" ;; --socket) echo "$socket" ;; --port) echo "$port" ;; diff --git a/scripts/mysql_convert_table_format.sh b/scripts/mysql_convert_table_format.sh index 5f3e093d2b9..d8258726347 100644 --- a/scripts/mysql_convert_table_format.sh +++ b/scripts/mysql_convert_table_format.sh @@ -125,7 +125,7 @@ sub usage print <<EOF; -Conversion of a MySQL tables to other storage engines +Conversion of a MariaDB tables to other storage engines Usage: $0 database [table[ table ...]] If no tables has been specifed, all tables in the database will be converted. diff --git a/scripts/mysql_find_rows.sh b/scripts/mysql_find_rows.sh index 48c4915ae00..8a163e0edf1 100644 --- a/scripts/mysql_find_rows.sh +++ b/scripts/mysql_find_rows.sh @@ -131,7 +131,7 @@ $0 Ver $version Prints all SQL queries that matches a regexp or contains a 'use database' or 'set ..' command to stdout. A SQL query may contain -newlines. This is useful to find things in a MySQL update log. +newlines. This is useful to find things in a MariaDB update log. $0 takes the following options: diff --git a/scripts/mysql_fix_extensions.sh b/scripts/mysql_fix_extensions.sh index 2a50bfe22bb..79a9461fbb4 100644 --- a/scripts/mysql_fix_extensions.sh +++ b/scripts/mysql_fix_extensions.sh @@ -18,10 +18,10 @@ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA -# This is a utility for MySQL. It is not needed by any standard part -# of MySQL. +# This is a utility for MariaDB. It is not needed by any standard part +# of MariaDB. -# Usage: mysql_fix_extentions datadir +# Usage: mysql_fix_extensions datadir # does not work with RAID, with InnoDB or BDB tables # makes .frm lowercase and .MYI/MYD/ISM/ISD uppercase # useful when datafiles are copied from windows diff --git a/scripts/mysql_install_db.pl.in b/scripts/mysql_install_db.pl.in index 4d3641397d0..8a3492c8756 100644 --- a/scripts/mysql_install_db.pl.in +++ b/scripts/mysql_install_db.pl.in @@ -348,8 +348,9 @@ if ( $opt->{srcdir} ) my $fill_help_tables = "$pkgdatadir/fill_help_tables.sql"; my $create_system_tables = "$pkgdatadir/mysql_system_tables.sql"; my $fill_system_tables = "$pkgdatadir/mysql_system_tables_data.sql"; +my $maria_add_gis_sp = "$pkgdatadir/maria_add_gis_sp_bootstrap.sql"; -foreach my $f ( $fill_help_tables,$create_system_tables,$fill_system_tables ) +foreach my $f ( $fill_help_tables,$create_system_tables,$fill_system_tables,$maria_add_gis_sp ) { -f $f or cannot_find_file($f); } @@ -496,6 +497,32 @@ if ( open(PIPE, "| $mysqld_install_cmd_line") ) "The \"HELP\" command might not work properly"); } + # ---------------------------------------------------------------------- + # Pipe maria_add_gis_sp.sql to "mysqld --bootstrap" + # ---------------------------------------------------------------------- + + report_verbose_wait($opt,"Creating OpenGIS required SP-s..."); + open(SQL, $maria_add_gis_sp) + or error($opt,"can't open $maria_add_gis_sp for reading: $!"); + # FIXME > /dev/null ? + if ( open(PIPE, "| $mysqld_install_cmd_line") ) + { + print PIPE "use test;\n"; + while ( <SQL> ) + { + print PIPE $_; + } + close PIPE; + close SQL; + + report_verbose($opt,"OK"); + } + else + { + warning($opt,"OPENGIS REQUIRED SP-S WERE NOT COMPLETELY INSTALLED!", + "GIS extentions might not work properly"); + } + report_verbose($opt,"To start mysqld at boot time you have to copy", "support-files/mysql.server to the right place " . "for your system"); diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 6cfe75961f3..15750ff5e90 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -307,8 +307,9 @@ fill_help_tables="$pkgdatadir/fill_help_tables.sql" create_system_tables="$pkgdatadir/mysql_system_tables.sql" create_system_tables2="$pkgdatadir/mysql_performance_tables.sql" fill_system_tables="$pkgdatadir/mysql_system_tables_data.sql" +maria_add_gis_sp="$pkgdatadir/maria_add_gis_sp_bootstrap.sql" -for f in "$fill_help_tables" "$create_system_tables" "$create_system_tables2" "$fill_system_tables" +for f in "$fill_help_tables" "$create_system_tables" "$create_system_tables2" "$fill_system_tables" "$maria_add_gis_sp" do if test ! -f "$f" then @@ -417,7 +418,7 @@ mysqld_install_cmd_line() { "$mysqld_bootstrap" $defaults "$mysqld_opt" --bootstrap \ "--basedir=$basedir" "--datadir=$ldata" --log-warnings=0 \ - --loose-skip-ndbcluster $args --max_allowed_packet=8M \ + $args --max_allowed_packet=8M \ --net_buffer_length=16K } @@ -469,6 +470,17 @@ else echo "The \"HELP\" command might not work properly." fi +s_echo "Creating OpenGIS required SP-s..." +if { echo "use test;"; cat "$maria_add_gis_sp"; } | mysqld_install_cmd_line > /dev/null +then + s_echo "OK" +else + echo + echo "WARNING: OPENGIS REQUIRED SP-S WERE NOT COMPLETELY INSTALLED!" + echo "GIS extentions might not work properly." +fi + + # Don't output verbose information if running inside bootstrap or using # --srcdir for testing. In such cases, there's no end user looking at # the screen. diff --git a/scripts/mysql_performance_tables.sql b/scripts/mysql_performance_tables.sql index d4955782e4d..306160355de 100644 --- a/scripts/mysql_performance_tables.sql +++ b/scripts/mysql_performance_tables.sql @@ -53,1427 +53,3 @@ SET @str = IF(@broken_pfs = 0, @cmd, 'SET @dummy = 0'); PREPARE stmt FROM @str; EXECUTE stmt; DROP PREPARE stmt; - --- --- From this point, only create the performance schema tables --- if the server is built with performance schema --- - -set @have_pfs= (select count(engine) from information_schema.engines where engine='PERFORMANCE_SCHEMA' and support != 'NO'); - --- --- TABLE COND_INSTANCES --- - -SET @cmd="CREATE TABLE performance_schema.cond_instances(" - "NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_CURRENT --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_current(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "SPINS INTEGER unsigned," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(512)," - "INDEX_NAME VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')," - "OPERATION VARCHAR(32) not null," - "NUMBER_OF_BYTES BIGINT," - "FLAGS INTEGER unsigned" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_HISTORY --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_history(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "SPINS INTEGER unsigned," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(512)," - "INDEX_NAME VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')," - "OPERATION VARCHAR(32) not null," - "NUMBER_OF_BYTES BIGINT," - "FLAGS INTEGER unsigned" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_HISTORY_LONG --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_history_long(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "SPINS INTEGER unsigned," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(512)," - "INDEX_NAME VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')," - "OPERATION VARCHAR(32) not null," - "NUMBER_OF_BYTES BIGINT," - "FLAGS INTEGER unsigned" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_BY_INSTANCE --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_instance(" - "EVENT_NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_host_by_event_name(" - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_BY_USER_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_user_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_account_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_thread_by_event_name(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_WAITS_SUMMARY_GLOBAL_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_waits_summary_global_by_event_name(" - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE FILE_INSTANCES --- - -SET @cmd="CREATE TABLE performance_schema.file_instances(" - "FILE_NAME VARCHAR(512) not null," - "EVENT_NAME VARCHAR(128) not null," - "OPEN_COUNT INTEGER unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE FILE_SUMMARY_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.file_summary_by_event_name(" - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_READ BIGINT not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_WRITE BIGINT not null," - "COUNT_MISC BIGINT unsigned not null," - "SUM_TIMER_MISC BIGINT unsigned not null," - "MIN_TIMER_MISC BIGINT unsigned not null," - "AVG_TIMER_MISC BIGINT unsigned not null," - "MAX_TIMER_MISC BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE FILE_SUMMARY_BY_INSTANCE --- - -SET @cmd="CREATE TABLE performance_schema.file_summary_by_instance(" - "FILE_NAME VARCHAR(512) not null," - "EVENT_NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_READ BIGINT not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_WRITE BIGINT not null," - "COUNT_MISC BIGINT unsigned not null," - "SUM_TIMER_MISC BIGINT unsigned not null," - "MIN_TIMER_MISC BIGINT unsigned not null," - "AVG_TIMER_MISC BIGINT unsigned not null," - "MAX_TIMER_MISC BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - - --- --- TABLE SOCKET_INSTANCES --- - -SET @cmd="CREATE TABLE performance_schema.socket_instances(" - "EVENT_NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "THREAD_ID BIGINT unsigned," - "SOCKET_ID INTEGER not null," - "IP VARCHAR(64) not null," - "PORT INTEGER not null," - "STATE ENUM('IDLE','ACTIVE') not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SOCKET_SUMMARY_BY_INSTANCE --- - -SET @cmd="CREATE TABLE performance_schema.socket_summary_by_instance(" - "EVENT_NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_READ BIGINT unsigned not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_WRITE BIGINT unsigned not null," - "COUNT_MISC BIGINT unsigned not null," - "SUM_TIMER_MISC BIGINT unsigned not null," - "MIN_TIMER_MISC BIGINT unsigned not null," - "AVG_TIMER_MISC BIGINT unsigned not null," - "MAX_TIMER_MISC BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SOCKET_SUMMARY_BY_INSTANCE --- - -SET @cmd="CREATE TABLE performance_schema.socket_summary_by_event_name(" - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_READ BIGINT unsigned not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "SUM_NUMBER_OF_BYTES_WRITE BIGINT unsigned not null," - "COUNT_MISC BIGINT unsigned not null," - "SUM_TIMER_MISC BIGINT unsigned not null," - "MIN_TIMER_MISC BIGINT unsigned not null," - "AVG_TIMER_MISC BIGINT unsigned not null," - "MAX_TIMER_MISC BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE HOST_CACHE --- - -SET @cmd="CREATE TABLE performance_schema.host_cache(" - "IP VARCHAR(64) not null," - "HOST VARCHAR(255) collate utf8_bin," - "HOST_VALIDATED ENUM ('YES', 'NO') not null," - "SUM_CONNECT_ERRORS BIGINT not null," - "COUNT_HOST_BLOCKED_ERRORS BIGINT not null," - "COUNT_NAMEINFO_TRANSIENT_ERRORS BIGINT not null," - "COUNT_NAMEINFO_PERMANENT_ERRORS BIGINT not null," - "COUNT_FORMAT_ERRORS BIGINT not null," - "COUNT_ADDRINFO_TRANSIENT_ERRORS BIGINT not null," - "COUNT_ADDRINFO_PERMANENT_ERRORS BIGINT not null," - "COUNT_FCRDNS_ERRORS BIGINT not null," - "COUNT_HOST_ACL_ERRORS BIGINT not null," - "COUNT_NO_AUTH_PLUGIN_ERRORS BIGINT not null," - "COUNT_AUTH_PLUGIN_ERRORS BIGINT not null," - "COUNT_HANDSHAKE_ERRORS BIGINT not null," - "COUNT_PROXY_USER_ERRORS BIGINT not null," - "COUNT_PROXY_USER_ACL_ERRORS BIGINT not null," - "COUNT_AUTHENTICATION_ERRORS BIGINT not null," - "COUNT_SSL_ERRORS BIGINT not null," - "COUNT_MAX_USER_CONNECTIONS_ERRORS BIGINT not null," - "COUNT_MAX_USER_CONNECTIONS_PER_HOUR_ERRORS BIGINT not null," - "COUNT_DEFAULT_DATABASE_ERRORS BIGINT not null," - "COUNT_INIT_CONNECT_ERRORS BIGINT not null," - "COUNT_LOCAL_ERRORS BIGINT not null," - "COUNT_UNKNOWN_ERRORS BIGINT not null," - "FIRST_SEEN TIMESTAMP(0) NOT NULL default 0," - "LAST_SEEN TIMESTAMP(0) NOT NULL default 0," - "FIRST_ERROR_SEEN TIMESTAMP(0) null default 0," - "LAST_ERROR_SEEN TIMESTAMP(0) null default 0" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE MUTEX_INSTANCES --- - -SET @cmd="CREATE TABLE performance_schema.mutex_instances(" - "NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "LOCKED_BY_THREAD_ID BIGINT unsigned" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE OBJECTS_SUMMARY_GLOBAL_BY_TYPE --- - -SET @cmd="CREATE TABLE performance_schema.objects_summary_global_by_type(" - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE PERFORMANCE_TIMERS --- - -SET @cmd="CREATE TABLE performance_schema.performance_timers(" - "TIMER_NAME ENUM ('CYCLE', 'NANOSECOND', 'MICROSECOND', 'MILLISECOND', 'TICK') not null," - "TIMER_FREQUENCY BIGINT," - "TIMER_RESOLUTION BIGINT," - "TIMER_OVERHEAD BIGINT" - ") ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE RWLOCK_INSTANCES --- - -SET @cmd="CREATE TABLE performance_schema.rwlock_instances(" - "NAME VARCHAR(128) not null," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned not null," - "WRITE_LOCKED_BY_THREAD_ID BIGINT unsigned," - "READ_LOCKED_BY_COUNT INTEGER unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SETUP_ACTORS --- - -SET @cmd="CREATE TABLE performance_schema.setup_actors(" - "HOST CHAR(60) collate utf8_bin default '%' not null," - "USER CHAR(16) collate utf8_bin default '%' not null," - "ROLE CHAR(16) collate utf8_bin default '%' not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SETUP_CONSUMERS --- - -SET @cmd="CREATE TABLE performance_schema.setup_consumers(" - "NAME VARCHAR(64) not null," - "ENABLED ENUM ('YES', 'NO') not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SETUP_INSTRUMENTS --- - -SET @cmd="CREATE TABLE performance_schema.setup_instruments(" - "NAME VARCHAR(128) not null," - "ENABLED ENUM ('YES', 'NO') not null," - "TIMED ENUM ('YES', 'NO') not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SETUP_OBJECTS --- - -SET @cmd="CREATE TABLE performance_schema.setup_objects(" - "OBJECT_TYPE ENUM ('TABLE') not null default 'TABLE'," - "OBJECT_SCHEMA VARCHAR(64) default '%'," - "OBJECT_NAME VARCHAR(64) not null default '%'," - "ENABLED ENUM ('YES', 'NO') not null default 'YES'," - "TIMED ENUM ('YES', 'NO') not null default 'YES'" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SETUP_TIMERS --- - -SET @cmd="CREATE TABLE performance_schema.setup_timers(" - "NAME VARCHAR(64) not null," - "TIMER_NAME ENUM ('CYCLE', 'NANOSECOND', 'MICROSECOND', 'MILLISECOND', 'TICK') not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE TABLE_IO_WAITS_SUMMARY_BY_INDEX_USAGE --- - -SET @cmd="CREATE TABLE performance_schema.table_io_waits_summary_by_index_usage(" - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "INDEX_NAME VARCHAR(64)," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "COUNT_FETCH BIGINT unsigned not null," - "SUM_TIMER_FETCH BIGINT unsigned not null," - "MIN_TIMER_FETCH BIGINT unsigned not null," - "AVG_TIMER_FETCH BIGINT unsigned not null," - "MAX_TIMER_FETCH BIGINT unsigned not null," - "COUNT_INSERT BIGINT unsigned not null," - "SUM_TIMER_INSERT BIGINT unsigned not null," - "MIN_TIMER_INSERT BIGINT unsigned not null," - "AVG_TIMER_INSERT BIGINT unsigned not null," - "MAX_TIMER_INSERT BIGINT unsigned not null," - "COUNT_UPDATE BIGINT unsigned not null," - "SUM_TIMER_UPDATE BIGINT unsigned not null," - "MIN_TIMER_UPDATE BIGINT unsigned not null," - "AVG_TIMER_UPDATE BIGINT unsigned not null," - "MAX_TIMER_UPDATE BIGINT unsigned not null," - "COUNT_DELETE BIGINT unsigned not null," - "SUM_TIMER_DELETE BIGINT unsigned not null," - "MIN_TIMER_DELETE BIGINT unsigned not null," - "AVG_TIMER_DELETE BIGINT unsigned not null," - "MAX_TIMER_DELETE BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE TABLE_IO_WAITS_SUMMARY_BY_TABLE --- - -SET @cmd="CREATE TABLE performance_schema.table_io_waits_summary_by_table(" - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "COUNT_FETCH BIGINT unsigned not null," - "SUM_TIMER_FETCH BIGINT unsigned not null," - "MIN_TIMER_FETCH BIGINT unsigned not null," - "AVG_TIMER_FETCH BIGINT unsigned not null," - "MAX_TIMER_FETCH BIGINT unsigned not null," - "COUNT_INSERT BIGINT unsigned not null," - "SUM_TIMER_INSERT BIGINT unsigned not null," - "MIN_TIMER_INSERT BIGINT unsigned not null," - "AVG_TIMER_INSERT BIGINT unsigned not null," - "MAX_TIMER_INSERT BIGINT unsigned not null," - "COUNT_UPDATE BIGINT unsigned not null," - "SUM_TIMER_UPDATE BIGINT unsigned not null," - "MIN_TIMER_UPDATE BIGINT unsigned not null," - "AVG_TIMER_UPDATE BIGINT unsigned not null," - "MAX_TIMER_UPDATE BIGINT unsigned not null," - "COUNT_DELETE BIGINT unsigned not null," - "SUM_TIMER_DELETE BIGINT unsigned not null," - "MIN_TIMER_DELETE BIGINT unsigned not null," - "AVG_TIMER_DELETE BIGINT unsigned not null," - "MAX_TIMER_DELETE BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE TABLE_LOCK_WAITS_SUMMARY_BY_TABLE --- - -SET @cmd="CREATE TABLE performance_schema.table_lock_waits_summary_by_table(" - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "COUNT_READ BIGINT unsigned not null," - "SUM_TIMER_READ BIGINT unsigned not null," - "MIN_TIMER_READ BIGINT unsigned not null," - "AVG_TIMER_READ BIGINT unsigned not null," - "MAX_TIMER_READ BIGINT unsigned not null," - "COUNT_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE BIGINT unsigned not null," - "COUNT_READ_NORMAL BIGINT unsigned not null," - "SUM_TIMER_READ_NORMAL BIGINT unsigned not null," - "MIN_TIMER_READ_NORMAL BIGINT unsigned not null," - "AVG_TIMER_READ_NORMAL BIGINT unsigned not null," - "MAX_TIMER_READ_NORMAL BIGINT unsigned not null," - "COUNT_READ_WITH_SHARED_LOCKS BIGINT unsigned not null," - "SUM_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null," - "MIN_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null," - "AVG_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null," - "MAX_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null," - "COUNT_READ_HIGH_PRIORITY BIGINT unsigned not null," - "SUM_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null," - "MIN_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null," - "AVG_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null," - "MAX_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null," - "COUNT_READ_NO_INSERT BIGINT unsigned not null," - "SUM_TIMER_READ_NO_INSERT BIGINT unsigned not null," - "MIN_TIMER_READ_NO_INSERT BIGINT unsigned not null," - "AVG_TIMER_READ_NO_INSERT BIGINT unsigned not null," - "MAX_TIMER_READ_NO_INSERT BIGINT unsigned not null," - "COUNT_READ_EXTERNAL BIGINT unsigned not null," - "SUM_TIMER_READ_EXTERNAL BIGINT unsigned not null," - "MIN_TIMER_READ_EXTERNAL BIGINT unsigned not null," - "AVG_TIMER_READ_EXTERNAL BIGINT unsigned not null," - "MAX_TIMER_READ_EXTERNAL BIGINT unsigned not null," - "COUNT_WRITE_ALLOW_WRITE BIGINT unsigned not null," - "SUM_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null," - "MIN_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null," - "AVG_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null," - "MAX_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null," - "COUNT_WRITE_CONCURRENT_INSERT BIGINT unsigned not null," - "SUM_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null," - "MIN_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null," - "AVG_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null," - "MAX_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null," - "COUNT_WRITE_DELAYED BIGINT unsigned not null," - "SUM_TIMER_WRITE_DELAYED BIGINT unsigned not null," - "MIN_TIMER_WRITE_DELAYED BIGINT unsigned not null," - "AVG_TIMER_WRITE_DELAYED BIGINT unsigned not null," - "MAX_TIMER_WRITE_DELAYED BIGINT unsigned not null," - "COUNT_WRITE_LOW_PRIORITY BIGINT unsigned not null," - "SUM_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null," - "MIN_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null," - "AVG_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null," - "MAX_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null," - "COUNT_WRITE_NORMAL BIGINT unsigned not null," - "SUM_TIMER_WRITE_NORMAL BIGINT unsigned not null," - "MIN_TIMER_WRITE_NORMAL BIGINT unsigned not null," - "AVG_TIMER_WRITE_NORMAL BIGINT unsigned not null," - "MAX_TIMER_WRITE_NORMAL BIGINT unsigned not null," - "COUNT_WRITE_EXTERNAL BIGINT unsigned not null," - "SUM_TIMER_WRITE_EXTERNAL BIGINT unsigned not null," - "MIN_TIMER_WRITE_EXTERNAL BIGINT unsigned not null," - "AVG_TIMER_WRITE_EXTERNAL BIGINT unsigned not null," - "MAX_TIMER_WRITE_EXTERNAL BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE THREADS --- - -SET @cmd="CREATE TABLE performance_schema.threads(" - "THREAD_ID BIGINT unsigned not null," - "NAME VARCHAR(128) not null," - "TYPE VARCHAR(10) not null," - "PROCESSLIST_ID BIGINT unsigned," - "PROCESSLIST_USER VARCHAR(16)," - "PROCESSLIST_HOST VARCHAR(60)," - "PROCESSLIST_DB VARCHAR(64)," - "PROCESSLIST_COMMAND VARCHAR(16)," - "PROCESSLIST_TIME BIGINT," - "PROCESSLIST_STATE VARCHAR(64)," - "PROCESSLIST_INFO LONGTEXT," - "PARENT_THREAD_ID BIGINT unsigned," - "ROLE VARCHAR(64)," - "INSTRUMENTED ENUM ('YES', 'NO') not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_CURRENT --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_current(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_HISTORY --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_history(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_HISTORY_LONG --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_history_long(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_SUMMARY_BY_THREAD_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_summary_by_thread_by_event_name(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_SUMMARY_BY_HOST_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_summary_by_host_by_event_name(" - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_summary_by_user_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_summary_by_account_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STAGES_SUMMARY_GLOBAL_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_stages_summary_global_by_event_name(" - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_CURRENT --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_current(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "LOCK_TIME bigint unsigned not null," - "SQL_TEXT LONGTEXT," - "DIGEST VARCHAR(32)," - "DIGEST_TEXT LONGTEXT," - "CURRENT_SCHEMA VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned," - "MYSQL_ERRNO INTEGER," - "RETURNED_SQLSTATE VARCHAR(5)," - "MESSAGE_TEXT VARCHAR(128)," - "ERRORS BIGINT unsigned not null," - "WARNINGS BIGINT unsigned not null," - "ROWS_AFFECTED BIGINT unsigned not null," - "ROWS_SENT BIGINT unsigned not null," - "ROWS_EXAMINED BIGINT unsigned not null," - "CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "CREATED_TMP_TABLES BIGINT unsigned not null," - "SELECT_FULL_JOIN BIGINT unsigned not null," - "SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SELECT_RANGE BIGINT unsigned not null," - "SELECT_RANGE_CHECK BIGINT unsigned not null," - "SELECT_SCAN BIGINT unsigned not null," - "SORT_MERGE_PASSES BIGINT unsigned not null," - "SORT_RANGE BIGINT unsigned not null," - "SORT_ROWS BIGINT unsigned not null," - "SORT_SCAN BIGINT unsigned not null," - "NO_INDEX_USED BIGINT unsigned not null," - "NO_GOOD_INDEX_USED BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_HISTORY --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_history(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "LOCK_TIME bigint unsigned not null," - "SQL_TEXT LONGTEXT," - "DIGEST VARCHAR(32)," - "DIGEST_TEXT LONGTEXT," - "CURRENT_SCHEMA VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned," - "MYSQL_ERRNO INTEGER," - "RETURNED_SQLSTATE VARCHAR(5)," - "MESSAGE_TEXT VARCHAR(128)," - "ERRORS BIGINT unsigned not null," - "WARNINGS BIGINT unsigned not null," - "ROWS_AFFECTED BIGINT unsigned not null," - "ROWS_SENT BIGINT unsigned not null," - "ROWS_EXAMINED BIGINT unsigned not null," - "CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "CREATED_TMP_TABLES BIGINT unsigned not null," - "SELECT_FULL_JOIN BIGINT unsigned not null," - "SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SELECT_RANGE BIGINT unsigned not null," - "SELECT_RANGE_CHECK BIGINT unsigned not null," - "SELECT_SCAN BIGINT unsigned not null," - "SORT_MERGE_PASSES BIGINT unsigned not null," - "SORT_RANGE BIGINT unsigned not null," - "SORT_ROWS BIGINT unsigned not null," - "SORT_SCAN BIGINT unsigned not null," - "NO_INDEX_USED BIGINT unsigned not null," - "NO_GOOD_INDEX_USED BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_HISTORY_LONG --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_history_long(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_ID BIGINT unsigned not null," - "END_EVENT_ID BIGINT unsigned," - "EVENT_NAME VARCHAR(128) not null," - "SOURCE VARCHAR(64)," - "TIMER_START BIGINT unsigned," - "TIMER_END BIGINT unsigned," - "TIMER_WAIT BIGINT unsigned," - "LOCK_TIME bigint unsigned not null," - "SQL_TEXT LONGTEXT," - "DIGEST VARCHAR(32)," - "DIGEST_TEXT LONGTEXT," - "CURRENT_SCHEMA VARCHAR(64)," - "OBJECT_TYPE VARCHAR(64)," - "OBJECT_SCHEMA VARCHAR(64)," - "OBJECT_NAME VARCHAR(64)," - "OBJECT_INSTANCE_BEGIN BIGINT unsigned," - "MYSQL_ERRNO INTEGER," - "RETURNED_SQLSTATE VARCHAR(5)," - "MESSAGE_TEXT VARCHAR(128)," - "ERRORS BIGINT unsigned not null," - "WARNINGS BIGINT unsigned not null," - "ROWS_AFFECTED BIGINT unsigned not null," - "ROWS_SENT BIGINT unsigned not null," - "ROWS_EXAMINED BIGINT unsigned not null," - "CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "CREATED_TMP_TABLES BIGINT unsigned not null," - "SELECT_FULL_JOIN BIGINT unsigned not null," - "SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SELECT_RANGE BIGINT unsigned not null," - "SELECT_RANGE_CHECK BIGINT unsigned not null," - "SELECT_SCAN BIGINT unsigned not null," - "SORT_MERGE_PASSES BIGINT unsigned not null," - "SORT_RANGE BIGINT unsigned not null," - "SORT_ROWS BIGINT unsigned not null," - "SORT_SCAN BIGINT unsigned not null," - "NO_INDEX_USED BIGINT unsigned not null," - "NO_GOOD_INDEX_USED BIGINT unsigned not null," - "NESTING_EVENT_ID BIGINT unsigned," - "NESTING_EVENT_TYPE ENUM('STATEMENT', 'STAGE', 'WAIT')" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_BY_THREAD_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_thread_by_event_name(" - "THREAD_ID BIGINT unsigned not null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_BY_HOST_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_host_by_event_name(" - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_BY_USER_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_user_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_account_by_event_name(" - "USER CHAR(16) collate utf8_bin default null," - "HOST CHAR(60) collate utf8_bin default null," - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_GLOBAL_BY_EVENT_NAME --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_global_by_event_name(" - "EVENT_NAME VARCHAR(128) not null," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE HOSTS --- - -SET @cmd="CREATE TABLE performance_schema.hosts(" - "HOST CHAR(60) collate utf8_bin default null," - "CURRENT_CONNECTIONS bigint not null," - "TOTAL_CONNECTIONS bigint not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE USERS --- - -SET @cmd="CREATE TABLE performance_schema.users(" - "USER CHAR(16) collate utf8_bin default null," - "CURRENT_CONNECTIONS bigint not null," - "TOTAL_CONNECTIONS bigint not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE ACCOUNTS --- - -SET @cmd="CREATE TABLE performance_schema.accounts(" - "USER CHAR(16) collate utf8_bin default null," - "HOST CHAR(60) collate utf8_bin default null," - "CURRENT_CONNECTIONS bigint not null," - "TOTAL_CONNECTIONS bigint not null" - ")ENGINE=PERFORMANCE_SCHEMA;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE EVENTS_STATEMENTS_SUMMARY_BY_DIGEST --- - -SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_digest(" - "SCHEMA_NAME VARCHAR(64)," - "DIGEST VARCHAR(32)," - "DIGEST_TEXT LONGTEXT," - "COUNT_STAR BIGINT unsigned not null," - "SUM_TIMER_WAIT BIGINT unsigned not null," - "MIN_TIMER_WAIT BIGINT unsigned not null," - "AVG_TIMER_WAIT BIGINT unsigned not null," - "MAX_TIMER_WAIT BIGINT unsigned not null," - "SUM_LOCK_TIME BIGINT unsigned not null," - "SUM_ERRORS BIGINT unsigned not null," - "SUM_WARNINGS BIGINT unsigned not null," - "SUM_ROWS_AFFECTED BIGINT unsigned not null," - "SUM_ROWS_SENT BIGINT unsigned not null," - "SUM_ROWS_EXAMINED BIGINT unsigned not null," - "SUM_CREATED_TMP_DISK_TABLES BIGINT unsigned not null," - "SUM_CREATED_TMP_TABLES BIGINT unsigned not null," - "SUM_SELECT_FULL_JOIN BIGINT unsigned not null," - "SUM_SELECT_FULL_RANGE_JOIN BIGINT unsigned not null," - "SUM_SELECT_RANGE BIGINT unsigned not null," - "SUM_SELECT_RANGE_CHECK BIGINT unsigned not null," - "SUM_SELECT_SCAN BIGINT unsigned not null," - "SUM_SORT_MERGE_PASSES BIGINT unsigned not null," - "SUM_SORT_RANGE BIGINT unsigned not null," - "SUM_SORT_ROWS BIGINT unsigned not null," - "SUM_SORT_SCAN BIGINT unsigned not null," - "SUM_NO_INDEX_USED BIGINT unsigned not null," - "SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null," - "FIRST_SEEN TIMESTAMP(0) NOT NULL default 0," - "LAST_SEEN TIMESTAMP(0) NOT NULL default 0" - ")ENGINE=PERFORMANCE_SCHEMA;"; - - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SESSION_CONNECT_ATTRS --- - -SET @cmd="CREATE TABLE performance_schema.session_connect_attrs(" - "PROCESSLIST_ID INT NOT NULL," - "ATTR_NAME VARCHAR(32) NOT NULL," - "ATTR_VALUE VARCHAR(1024)," - "ORDINAL_POSITION INT" - ")ENGINE=PERFORMANCE_SCHEMA CHARACTER SET utf8 COLLATE utf8_bin;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; - --- --- TABLE SESSION_ACCOUNT_CONNECT_ATTRS --- - -SET @cmd="CREATE TABLE performance_schema.session_account_connect_attrs " - " LIKE performance_schema.session_connect_attrs;"; - -SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0'); -PREPARE stmt FROM @str; -EXECUTE stmt; -DROP PREPARE stmt; diff --git a/scripts/mysql_setpermission.sh b/scripts/mysql_setpermission.sh index 48f0b09b566..6e9d0e9fabe 100644 --- a/scripts/mysql_setpermission.sh +++ b/scripts/mysql_setpermission.sh @@ -78,7 +78,7 @@ else if ($opt_password eq '') { system "stty -echo"; - print "Password for user $opt_user to connect to MySQL: "; + print "Password for user $opt_user to connect to MariaDB: "; $opt_password = <STDIN>; chomp($opt_password); system "stty echo"; @@ -86,7 +86,7 @@ if ($opt_password eq '') } -# make the connection to MySQL +# make the connection to MariaDB $dbh= DBI->connect("DBI:mysql:mysql:host=$sqlhost:port=$opt_port:mysql_socket=$opt_socket",$opt_user,$opt_password, {PrintError => 0}) || die("Can't make a connection to the mysql server.\n The error: $DBI::errstr"); @@ -106,7 +106,7 @@ sub q1 { # first question ... while (! $end) { print "#"x70; print "\n"; - print "## Welcome to the permission setter $version for MySQL.\n"; + print "## Welcome to the permission setter $version for MariaDB.\n"; print "## made by Luuk de Boer\n"; print "#"x70; print "\n"; @@ -634,17 +634,17 @@ sub usage { print <<EOL; ---------------------------------------------------------------------- - The permission setter for MySQL. + The permission setter for MariaDB. version: $version made by: Luuk de Boer <luuk\@wxs.nl> ---------------------------------------------------------------------- The permission setter is a little program which can help you add users -or databases or change passwords in MySQL. Keep in mind that we don't -check permissions which already been set in MySQL. So if you can't -connect to MySQL using the permission you just added, take a look at -the permissions which have already been set in MySQL. +or databases or change passwords in MariaDB. Keep in mind that we don't +check permissions which already been set in MariaDB. So if you can't +connect to MariaDB using the permission you just added, take a look at +the permissions which have already been set in MariaDB. The permission setter first reads your .my.cnf file in your Home directory if it exists. @@ -653,7 +653,7 @@ Options for the permission setter: --help : print this help message and exit. -The options shown below are used for making the connection to the MySQL +The options shown below are used for making the connection to the MariaDB server. Keep in mind that the permissions for the user specified via these options must be sufficient to add users / create databases / set passwords. diff --git a/scripts/mysql_system_tables.sql b/scripts/mysql_system_tables.sql index bc89ae82dbb..eea65f285d3 100644 --- a/scripts/mysql_system_tables.sql +++ b/scripts/mysql_system_tables.sql @@ -33,7 +33,7 @@ set @had_db_table= @@warning_count != 0; CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; -CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, is_role enum('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; +CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, is_role enum('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, default_role char(80) binary DEFAULT '' NOT NULL, max_statement_time decimal(12,6) DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; -- Remember for later if user table already existed set @had_user_table= @@warning_count != 0; @@ -95,7 +95,7 @@ DROP PREPARE stmt; -- Create slow_log if CSV is enabled. -SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, query_time TIME(6) NOT NULL, lock_time TIME(6) NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0'); +SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, query_time TIME(6) NOT NULL, lock_time TIME(6) NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL, rows_affected INTEGER NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0'); PREPARE stmt FROM @str; EXECUTE stmt; diff --git a/scripts/mysql_system_tables_data.sql b/scripts/mysql_system_tables_data.sql index 38e6a547c1d..075aafd5e3b 100644 --- a/scripts/mysql_system_tables_data.sql +++ b/scripts/mysql_system_tables_data.sql @@ -39,10 +39,10 @@ DROP TABLE tmp_db; -- Fill "user" table with default users allowing root access -- from local machine if "user" table didn't exist before CREATE TEMPORARY TABLE tmp_user LIKE user; -INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N', 'N'); -REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N' FROM dual WHERE @current_hostname != 'localhost'; -REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N'); -REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N'); +INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N', 'N','', 0); +REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N','',0 FROM dual WHERE @current_hostname != 'localhost'; +REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N','',0); +REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','N','N', '', 0); INSERT INTO tmp_user (host,user) VALUES ('localhost',''); INSERT INTO tmp_user (host,user) SELECT @current_hostname,'' FROM dual WHERE @current_hostname != 'localhost'; INSERT INTO user SELECT * FROM tmp_user WHERE @had_user_table=0; diff --git a/scripts/mysql_system_tables_fix.sql b/scripts/mysql_system_tables_fix.sql index b81eb4e8e40..8d2a563c0d1 100644 --- a/scripts/mysql_system_tables_fix.sql +++ b/scripts/mysql_system_tables_fix.sql @@ -1,5 +1,5 @@ -- Copyright (C) 2003, 2013 Oracle and/or its affiliates. --- Copyright (C) 2010, 2014 SkySQL Ab. +-- Copyright (C) 2010, 2015 MariaDB Corporation. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -14,8 +14,10 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# This part converts any old privilege tables to privilege tables suitable -# for current version of MySQL +# WARNING: Do not use this script to upgrade system tables older that v5.1. + +# This part converts old privilege tables to privilege tables suitable +# for current version of MySQL/MariaDB server. # You can safely ignore all 'Duplicate column' and 'Unknown column' errors # because these just mean that your tables are already up to date. @@ -27,213 +29,9 @@ set sql_mode=''; set storage_engine=MyISAM; -ALTER TABLE user add File_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL; - -# Detect whether or not we had the Grant_priv column -SET @hadGrantPriv:=0; -SELECT @hadGrantPriv:=1 FROM user WHERE Grant_priv LIKE '%'; - -ALTER TABLE user add Grant_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add References_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Index_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Alter_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL; -ALTER TABLE host add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Index_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Alter_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL; -ALTER TABLE db add Grant_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add References_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Index_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL,add Alter_priv enum('N','Y') COLLATE utf8_general_ci NOT NULL; - -# Fix privileges for old tables -UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0; -UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0; -UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE @hadGrantPriv = 0; - -# -# The second alter changes ssl_type to new 4.0.2 format -# Adding columns needed by GRANT .. REQUIRE (openssl) - -ALTER TABLE user -ADD ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci NOT NULL, -ADD ssl_cipher BLOB NOT NULL, -ADD x509_issuer BLOB NOT NULL, -ADD x509_subject BLOB NOT NULL; -ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL; - -# -# tables_priv -# -ALTER TABLE tables_priv - ADD KEY Grantor (Grantor); - -ALTER TABLE tables_priv - MODIFY Host char(60) NOT NULL default '', - MODIFY Db char(64) NOT NULL default '', - MODIFY User char(80) NOT NULL default '', - MODIFY Table_name char(64) NOT NULL default '', - MODIFY Grantor char(141) NOT NULL default '', - ENGINE=MyISAM, - CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; - -ALTER TABLE tables_priv - MODIFY Column_priv set('Select','Insert','Update','References') - COLLATE utf8_general_ci DEFAULT '' NOT NULL, - MODIFY Table_priv set('Select','Insert','Update','Delete','Create', - 'Drop','Grant','References','Index','Alter', - 'Create View','Show view','Trigger') - COLLATE utf8_general_ci DEFAULT '' NOT NULL, - COMMENT='Table privileges'; - -# -# columns_priv -# -# -# Name change of Type -> Column_priv from MySQL 3.22.12 -# -ALTER TABLE columns_priv - CHANGE Type Column_priv set('Select','Insert','Update','References') - COLLATE utf8_general_ci DEFAULT '' NOT NULL; - -ALTER TABLE columns_priv - MODIFY Host char(60) NOT NULL default '', - MODIFY Db char(64) NOT NULL default '', - MODIFY User char(80) NOT NULL default '', - MODIFY Table_name char(64) NOT NULL default '', - MODIFY Column_name char(64) NOT NULL default '', - ENGINE=MyISAM, - CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin, - COMMENT='Column privileges'; - -ALTER TABLE columns_priv - MODIFY Column_priv set('Select','Insert','Update','References') - COLLATE utf8_general_ci DEFAULT '' NOT NULL; - -# -# Add the new 'type' column to the func table. -# - -ALTER TABLE func add type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL; - -# -# Change the user,db and host tables to current format -# - -# Detect whether we had Show_db_priv -SET @hadShowDbPriv:=0; -SELECT @hadShowDbPriv:=1 FROM user WHERE Show_db_priv LIKE '%'; - -ALTER TABLE user -ADD Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_priv, -ADD Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_db_priv, -ADD Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Super_priv, -ADD Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_tmp_table_priv, -ADD Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Lock_tables_priv, -ADD Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Execute_priv, -ADD Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Repl_slave_priv; - -# Convert privileges so that users have similar privileges as before - -UPDATE user SET Show_db_priv= Select_priv, Super_priv=Process_priv, Execute_priv=Process_priv, Create_tmp_table_priv='Y', Lock_tables_priv='Y', Repl_slave_priv=file_priv, Repl_client_priv=File_priv where user<>"" AND @hadShowDbPriv = 0; - - -# Add fields that can be used to limit number of questions and connections -# for some users. - -ALTER TABLE user -ADD max_questions int(11) NOT NULL DEFAULT 0 AFTER x509_subject, -ADD max_updates int(11) unsigned NOT NULL DEFAULT 0 AFTER max_questions, -ADD max_connections int(11) unsigned NOT NULL DEFAULT 0 AFTER max_updates; - - -# -# Add Create_tmp_table_priv and Lock_tables_priv to db and host -# - -ALTER TABLE db -ADD Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, -ADD Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; -ALTER TABLE host -ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, -ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL; - -alter table user change max_questions max_questions int(11) unsigned DEFAULT 0 NOT NULL; - - -alter table db comment='Database privileges'; -alter table host comment='Host privileges; Merged with database privileges'; -alter table user comment='Users and global privileges'; -alter table func comment='User defined functions'; - -# Convert all tables to UTF-8 with binary collation -# and reset all char columns to correct width -ALTER TABLE user - MODIFY Host char(60) NOT NULL default '', - MODIFY User char(80) NOT NULL default '', - ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; -ALTER TABLE user - MODIFY Password char(41) character set latin1 collate latin1_bin NOT NULL default '', - MODIFY Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL; - -ALTER TABLE db - MODIFY Host char(60) NOT NULL default '', - MODIFY Db char(64) NOT NULL default '', - MODIFY User char(80) NOT NULL default '', - ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; -ALTER TABLE db - MODIFY Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; - -ALTER TABLE host - MODIFY Host char(60) NOT NULL default '', - MODIFY Db char(64) NOT NULL default '', - ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; -ALTER TABLE host - MODIFY Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, - MODIFY Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; - -ALTER TABLE func - ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; -ALTER TABLE func - MODIFY type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL; - # # Modify log tables. # - SET @old_log_state = @@global.general_log; SET GLOBAL general_log = 'OFF'; ALTER TABLE general_log @@ -251,6 +49,8 @@ SET GLOBAL slow_query_log = 'OFF'; ALTER TABLE slow_log ADD COLUMN thread_id BIGINT(21) UNSIGNED NOT NULL AFTER sql_text; ALTER TABLE slow_log + ADD COLUMN rows_affected INTEGER NOT NULL AFTER thread_id; +ALTER TABLE slow_log MODIFY start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, MODIFY user_host MEDIUMTEXT NOT NULL, MODIFY query_time TIME(6) NOT NULL, @@ -265,131 +65,30 @@ ALTER TABLE slow_log MODIFY thread_id BIGINT(21) UNSIGNED NOT NULL; SET GLOBAL slow_query_log = @old_log_state; +# +# Modify plugin table. +# ALTER TABLE plugin MODIFY name varchar(64) COLLATE utf8_general_ci NOT NULL DEFAULT '', MODIFY dl varchar(128) COLLATE utf8_general_ci NOT NULL DEFAULT '', CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; # -# Detect whether we had Create_view_priv -# -SET @hadCreateViewPriv:=0; -SELECT @hadCreateViewPriv:=1 FROM user WHERE Create_view_priv LIKE '%'; - -# -# Create VIEWs privileges (v5.0) -# -ALTER TABLE db ADD Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Lock_tables_priv; -ALTER TABLE db MODIFY Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Lock_tables_priv; - -ALTER TABLE host ADD Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Lock_tables_priv; -ALTER TABLE host MODIFY Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Lock_tables_priv; - -ALTER TABLE user ADD Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Repl_client_priv; -ALTER TABLE user MODIFY Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Repl_client_priv; - -# -# Show VIEWs privileges (v5.0) -# -ALTER TABLE db ADD Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; -ALTER TABLE db MODIFY Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; - -ALTER TABLE host ADD Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; -ALTER TABLE host MODIFY Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; - -ALTER TABLE user ADD Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; -ALTER TABLE user MODIFY Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_view_priv; - -# -# Assign create/show view privileges to people who have create provileges -# -UPDATE user SET Create_view_priv=Create_priv, Show_view_priv=Create_priv where user<>"" AND @hadCreateViewPriv = 0; - -# -# -# -SET @hadCreateRoutinePriv:=0; -SELECT @hadCreateRoutinePriv:=1 FROM user WHERE Create_routine_priv LIKE '%'; - -# -# Create PROCEDUREs privileges (v5.0) -# -ALTER TABLE db ADD Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; -ALTER TABLE db MODIFY Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; - -ALTER TABLE host ADD Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; -ALTER TABLE host MODIFY Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; - -ALTER TABLE user ADD Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; -ALTER TABLE user MODIFY Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Show_view_priv; - -# -# Alter PROCEDUREs privileges (v5.0) -# -ALTER TABLE db ADD Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; -ALTER TABLE db MODIFY Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; - -ALTER TABLE host ADD Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; -ALTER TABLE host MODIFY Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; - -ALTER TABLE user ADD Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; -ALTER TABLE user MODIFY Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_routine_priv; - -ALTER TABLE db ADD Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; -ALTER TABLE db MODIFY Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; - -ALTER TABLE host ADD Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; -ALTER TABLE host MODIFY Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; - -# -# Assign create/alter routine privileges to people who have create privileges -# -UPDATE user SET Create_routine_priv=Create_priv, Alter_routine_priv=Alter_priv where user<>"" AND @hadCreateRoutinePriv = 0; -UPDATE db SET Create_routine_priv=Create_priv, Alter_routine_priv=Alter_priv, Execute_priv=Select_priv where user<>"" AND @hadCreateRoutinePriv = 0; -UPDATE host SET Create_routine_priv=Create_priv, Alter_routine_priv=Alter_priv, Execute_priv=Select_priv where @hadCreateRoutinePriv = 0; - -# -# Add max_user_connections resource limit -# this is signed in MariaDB so that if one sets it's to -1 then the user -# can't connect anymore. +# Add max_user_connections resource limit. +# This is signed in MariaDB so that if one sets it to -1 then the user +# cannot connect anymore. # ALTER TABLE user ADD max_user_connections int(11) DEFAULT '0' NOT NULL AFTER max_connections; ALTER TABLE user MODIFY max_user_connections int(11) DEFAULT '0' NOT NULL AFTER max_connections; # -# user.Create_user_priv -# - -SET @hadCreateUserPriv:=0; -SELECT @hadCreateUserPriv:=1 FROM user WHERE Create_user_priv LIKE '%'; - -ALTER TABLE user ADD Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; -ALTER TABLE user MODIFY Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; -UPDATE user LEFT JOIN db USING (Host,User) SET Create_user_priv='Y' - WHERE @hadCreateUserPriv = 0 AND - (user.Grant_priv = 'Y' OR db.Grant_priv = 'Y'); - -# # procs_priv # - -ALTER TABLE procs_priv - ENGINE=MyISAM, - CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin; - -ALTER TABLE procs_priv - MODIFY Proc_priv set('Execute','Alter Routine','Grant') - COLLATE utf8_general_ci DEFAULT '' NOT NULL; - ALTER IGNORE TABLE procs_priv MODIFY Routine_name char(64) COLLATE utf8_general_ci DEFAULT '' NOT NULL; ALTER TABLE procs_priv - ADD Routine_type enum('FUNCTION','PROCEDURE') - COLLATE utf8_general_ci NOT NULL AFTER Routine_name; - -ALTER TABLE procs_priv MODIFY Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER Proc_priv; # @@ -397,16 +96,7 @@ ALTER TABLE procs_priv # # Correct the name fields to not binary, and expand sql_data_access -ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL, - MODIFY specific_name char(64) DEFAULT '' NOT NULL, - MODIFY sql_data_access - enum('CONTAINS_SQL', - 'NO_SQL', - 'READS_SQL_DATA', - 'MODIFIES_SQL_DATA' - ) DEFAULT 'CONTAINS_SQL' NOT NULL, - MODIFY body longblob NOT NULL, - MODIFY returns longblob NOT NULL, +ALTER TABLE proc MODIFY returns longblob NOT NULL, MODIFY sql_mode set('REAL_AS_FLOAT', 'PIPES_AS_CONCAT', @@ -443,15 +133,9 @@ ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL, ) DEFAULT '' NOT NULL, DEFAULT CHARACTER SET utf8; -# Correct the character set and collation -ALTER TABLE proc CONVERT TO CHARACTER SET utf8; # Reset some fields after the conversion -ALTER TABLE proc MODIFY db - char(64) collate utf8_bin DEFAULT '' NOT NULL, - MODIFY definer - char(141) collate utf8_bin DEFAULT '' NOT NULL, - MODIFY comment - char(64) collate utf8_bin DEFAULT '' NOT NULL; +ALTER TABLE proc MODIFY definer + char(141) collate utf8_bin DEFAULT '' NOT NULL; ALTER TABLE proc ADD character_set_client char(32) collate utf8_bin DEFAULT NULL @@ -510,26 +194,8 @@ ALTER TABLE proc MODIFY comment text collate utf8_bin NOT NULL; # -# EVENT privilege -# -SET @hadEventPriv := 0; -SELECT @hadEventPriv :=1 FROM user WHERE Event_priv LIKE '%'; - -ALTER TABLE user add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL AFTER Create_user_priv; -ALTER TABLE user MODIFY Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL AFTER Create_user_priv; - -UPDATE user SET Event_priv=Super_priv WHERE @hadEventPriv = 0; - -ALTER TABLE db add Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL; -ALTER TABLE db MODIFY Event_priv enum('N','Y') character set utf8 DEFAULT 'N' NOT NULL; - -# # EVENT table # -ALTER TABLE event DROP PRIMARY KEY; -ALTER TABLE event ADD PRIMARY KEY(db, name); -# Add sql_mode column just in case. -ALTER TABLE event ADD sql_mode set ('IGNORE_BAD_TABLE_OPTIONS') AFTER on_completion; # Update list of sql_mode values. ALTER TABLE event MODIFY sql_mode set('REAL_AS_FLOAT', @@ -565,16 +231,12 @@ ALTER TABLE event MODIFY sql_mode 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH' ) DEFAULT '' NOT NULL AFTER on_completion; -ALTER TABLE event MODIFY name char(64) CHARACTER SET utf8 NOT NULL default ''; ALTER TABLE event MODIFY COLUMN originator INT UNSIGNED NOT NULL; ALTER TABLE event ADD COLUMN originator INT UNSIGNED NOT NULL AFTER comment; ALTER TABLE event MODIFY COLUMN status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED'; -ALTER TABLE event ADD COLUMN time_zone char(64) CHARACTER SET latin1 - NOT NULL DEFAULT 'SYSTEM' AFTER originator; - ALTER TABLE event ADD character_set_client char(32) collate utf8_bin DEFAULT NULL AFTER time_zone; @@ -597,25 +259,6 @@ ALTER TABLE event ADD body_utf8 longblob DEFAULT NULL AFTER db_collation; ALTER TABLE event MODIFY body_utf8 longblob DEFAULT NULL; - -# -# TRIGGER privilege -# - -SET @hadTriggerPriv := 0; -SELECT @hadTriggerPriv :=1 FROM user WHERE Trigger_priv LIKE '%'; - -ALTER TABLE user ADD Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Event_priv; -ALTER TABLE user MODIFY Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Event_priv; - -ALTER TABLE host ADD Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; -ALTER TABLE host MODIFY Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; - -ALTER TABLE db ADD Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; -ALTER TABLE db MODIFY Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; - -UPDATE user SET Trigger_priv=Super_priv WHERE @hadTriggerPriv = 0; - # # user.Create_tablespace_priv # @@ -631,6 +274,8 @@ UPDATE user SET Create_tablespace_priv = Super_priv WHERE @hadCreateTablespacePr ALTER TABLE user ADD plugin char(64) DEFAULT '', ADD authentication_string TEXT; ALTER TABLE user ADD password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; ALTER TABLE user ADD is_role enum('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL; +ALTER TABLE user ADD default_role char(80) binary DEFAULT '' NOT NULL; +ALTER TABLE user ADD max_statement_time decimal(12,6) DEFAULT 0 NOT NULL; ALTER TABLE user MODIFY plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, MODIFY authentication_string TEXT NOT NULL; -- Somewhere above, we ran ALTER TABLE user .... CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin. -- we want password_expired column to have collation utf8_general_ci. @@ -671,6 +316,11 @@ set @str=if(@have_innodb <> 0, @str, "set @dummy = 0"); prepare stmt from @str; execute stmt; +set @str="alter table mysql.innodb_table_stats modify last_update timestamp not null default current_timestamp on update current_timestamp"; +set @str=if(@have_innodb <> 0, @str, "set @dummy = 0"); +prepare stmt from @str; +execute stmt; + set @str=replace(@str, "innodb_index_stats", "innodb_table_stats"); prepare stmt from @str; execute stmt; @@ -696,7 +346,7 @@ alter table servers modify Username char(80) not null alter table procs_priv modify Grantor char(141) COLLATE utf8_bin not null default ''; alter table tables_priv modify Grantor char(141) COLLATE utf8_bin not null default ''; -# Activate the new, possible modified privilege tables +# Activate the new, possibly modified privilege tables. # This should not be needed, but gives us some extra testing that the above # changes was correct diff --git a/scripts/mysql_zap.sh b/scripts/mysql_zap.sh index a9c3e7a7f5a..98c3603df15 100644 --- a/scripts/mysql_zap.sh +++ b/scripts/mysql_zap.sh @@ -15,8 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# This is a utility for MySQL. It is not needed by any standard part -# of MySQL. +# This is a utility for MariaDB. It is not needed by any standard part +# of MariaDB. # Usage: mysql_zap [-signal] [-f] [-t] pattern diff --git a/scripts/mysqlaccess.sh b/scripts/mysqlaccess.sh index d8fd239585c..6fc090ab972 100644 --- a/scripts/mysqlaccess.sh +++ b/scripts/mysqlaccess.sh @@ -34,7 +34,7 @@ BEGIN { $script_log = $ENV{'HOME'}."/$script.log"; # **************************** - # information on MySQL + # information on MariaDB $MYSQL = '@bindir@/mysql'; # path to mysql executable $SERVER = '3.21'; $MYSQL_OPT = ' --batch --unbuffered'; @@ -97,8 +97,8 @@ Usage: $script [host [user [db]]] OPTIONS -U, --superuser=# connect as superuser -P, --spassword=# password for superuser - -H, --rhost=# remote MySQL-server to connect to - --old_server connect to old MySQL-server (before v3.21) which + -H, --rhost=# remote MariaDB-server to connect to + --old_server connect to old MariaDB-server (before v3.21) which does not yet know how to handle full where clauses. -b, --brief single-line tabular report diff --git a/scripts/mysqld_multi.sh b/scripts/mysqld_multi.sh index c567d434047..e3f8e50122c 100644 --- a/scripts/mysqld_multi.sh +++ b/scripts/mysqld_multi.sh @@ -38,7 +38,7 @@ use Getopt::Long; use POSIX qw(strftime getcwd); $|=1; -$VER="2.16"; +$VER="2.20"; my @defaults_options; # Leading --no-defaults, --defaults-file, etc. @@ -103,7 +103,7 @@ sub main print "WARNING: my_print_defaults command not found.\n"; print "Please make sure you have this command available and\n"; print "in your path. The command is available from the latest\n"; - print "MySQL distribution.\n"; + print "MariaDB distribution.\n"; $my_print_defaults_exists= 0; } @@ -138,6 +138,7 @@ sub main print "will be disabled\nand some will be enabled.\n\n"; } + init_log() if (!defined($opt_log)); $groupids = $ARGV[1]; if ($opt_version) { @@ -153,7 +154,7 @@ sub main if (!defined(my_which(my_print_defaults))) { print "ABORT: Can't find command 'my_print_defaults'.\n"; - print "This command is available from the latest MySQL\n"; + print "This command is available from the latest MariaDB\n"; print "distribution. Please make sure you have the command\n"; print "in your PATH.\n"; exit(1); @@ -163,7 +164,6 @@ sub main !($ARGV[0] =~ m/^stop$/i) && !($ARGV[0] =~ m/^report$/i))); - init_log() if (!defined($opt_log)); if (!$opt_no_log) { w2log("$my_progname log file version $VER; run: ", @@ -218,6 +218,10 @@ sub quote_shell_word return $option; } +#### +#### get options for a group +#### + sub defaults_for_group { my ($group) = @_; @@ -265,17 +269,17 @@ sub init_log } #### -#### Report living and not running MySQL servers +#### Report living and not running MariaDB servers #### sub report_mysqlds { my (@groups, $com, $i, @options, $pec); - print "Reporting MySQL servers\n"; + print "Reporting MariaDB servers\n"; if (!$opt_no_log) { - w2log("\nReporting MySQL servers","$opt_log",0,0); + w2log("\nReporting MariaDB servers","$opt_log",0,0); } @groups = &find_groups($groupids); for ($i = 0; defined($groups[$i]); $i++) @@ -286,19 +290,19 @@ sub report_mysqlds $pec = $? >> 8; if ($pec) { - print "MySQL server from group: $groups[$i] is not running\n"; + print "MariaDB server from group: $groups[$i] is not running\n"; if (!$opt_no_log) { - w2log("MySQL server from group: $groups[$i] is not running", + w2log("MariaDB server from group: $groups[$i] is not running", "$opt_log", 0, 0); } } else { - print "MySQL server from group: $groups[$i] is running\n"; + print "MariaDB server from group: $groups[$i] is running\n"; if (!$opt_no_log) { - w2log("MySQL server from group: $groups[$i] is running", + w2log("MariaDB server from group: $groups[$i] is running", "$opt_log", 0, 0); } } @@ -323,11 +327,11 @@ sub start_mysqlds() if (!$opt_no_log) { - w2log("\nStarting MySQL servers\n","$opt_log",0,0); + w2log("\nStarting MariaDB servers\n","$opt_log",0,0); } else { - print "\nStarting MySQL servers\n"; + print "\nStarting MariaDB servers\n"; } @groups = &find_groups($groupids); for ($i = 0; defined($groups[$i]); $i++) @@ -398,7 +402,7 @@ sub start_mysqlds() } if (!$i && !$opt_no_log) { - w2log("No MySQL servers to be started (check your GNRs)", + w2log("No MariaDB servers to be started (check your GNRs)", "$opt_log", 0, 0); } } @@ -413,11 +417,11 @@ sub stop_mysqlds() if (!$opt_no_log) { - w2log("\nStopping MySQL servers\n","$opt_log",0,0); + w2log("\nStopping MariaDB servers\n","$opt_log",0,0); } else { - print "\nStopping MySQL servers\n"; + print "\nStopping MariaDB servers\n"; } @groups = &find_groups($groupids); for ($i = 0; defined($groups[$i]); $i++) @@ -430,7 +434,7 @@ sub stop_mysqlds() } if (!$i && !$opt_no_log) { - w2log("No MySQL servers to be stopped (check your GNRs)", + w2log("No MariaDB servers to be stopped (check your GNRs)", "$opt_log", 0, 0); } } @@ -638,23 +642,23 @@ sub example # # 1.COMMON USER # -# Make sure that the MySQL user, who is stopping the mysqld services, has -# the same password to all MySQL servers being accessed by $my_progname. +# Make sure that the MariaDB user, who is stopping the mysqld services, has +# the same password to all MariaDB servers being accessed by $my_progname. # This user needs to have the 'Shutdown_priv' -privilege, but for security # reasons should have no other privileges. It is advised that you create a -# common 'multi_admin' user for all MySQL servers being controlled by +# common 'multi_admin' user for all MariaDB servers being controlled by # $my_progname. Here is an example how to do it: # # GRANT SHUTDOWN ON *.* TO multi_admin\@localhost IDENTIFIED BY 'password' # -# You will need to apply the above to all MySQL servers that are being +# You will need to apply the above to all MariaDB servers that are being # controlled by $my_progname. 'multi_admin' will shutdown the servers # using 'mysqladmin' -binary, when '$my_progname stop' is being called. # # 2.PID-FILE # # If you are using mysqld_safe to start mysqld, make sure that every -# MySQL server has a separate pid-file. In order to use mysqld_safe +# MariaDB server has a separate pid-file. In order to use mysqld_safe # via $my_progname, you need to use two options: # # mysqld=/path/to/mysqld_safe @@ -667,7 +671,7 @@ sub example # # 3.DATA DIRECTORY # -# It is NOT advised to run many MySQL servers within the same data directory. +# It is NOT advised to run many MariaDB servers within the same data directory. # You can do so, but please make sure to understand and deal with the # underlying caveats. In short they are: # - Speed penalty @@ -688,7 +692,7 @@ sub example # intentionally left out. You may have 'gaps' in the config file. This # gives you more flexibility. # -# 6.MySQL Server User +# 6.MariaDB Server User # # You can pass the user=... option inside [mysqld#] groups. This # can be very handy in some cases, but then you need to run $my_progname @@ -696,7 +700,7 @@ sub example # # 7.A Start-up Manage Script for $my_progname # -# In the recent MySQL distributions you can find a file called +# In the recent MariaDB distributions you can find a file called # mysqld_multi.server.sh. It is a wrapper for $my_progname. This can # be used to start and stop multiple servers during boot and shutdown. # @@ -709,7 +713,7 @@ sub example # or /root/.my.cnf and add the [mysqld_multi] and [mysqld#] groups. # # The script can be found from support-files/mysqld_multi.server.sh -# in MySQL distribution. (Verify the script before using) +# in MariaDB distribution. (Verify the script before using) # [mysqld_multi] @@ -828,7 +832,7 @@ Using: @{[join ' ', @defaults_options]} file is turned on. --password=... Password for mysqladmin user. --silent Disable warnings. ---tcp-ip Connect to the MySQL server(s) via the TCP/IP port instead +--tcp-ip Connect to the MariaDB server(s) via the TCP/IP port instead of the UNIX socket. This affects stopping and reporting. If a socket file is missing, the server may still be running, but can be accessed only via the TCP/IP port. diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index fdb4464a98f..a98abe6629b 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -20,6 +20,7 @@ mysqld_ld_preload= mysqld_ld_library_path= flush_caches=0 numa_interleave=0 +wsrep_on=0 # Initial logging status: error log is not open, and not using syslog logging=init @@ -154,7 +155,7 @@ log_notice () { } eval_log_error () { - cmd="$1" + local cmd="$1" case $logging in file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;; syslog) @@ -190,6 +191,89 @@ shell_quote_string() { echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g' } +wsrep_pick_url() { + [ $# -eq 0 ] && return 0 + + log_error "WSREP: 'wsrep_urls' is DEPRECATED! Use wsrep_cluster_address to specify multiple addresses instead." + + if ! which nc >/dev/null; then + log_error "ERROR: nc tool not found in PATH! Make sure you have it installed." + return 1 + fi + + local url + # Assuming URL in the form scheme://host:port + # If host and port are not NULL, the liveness of URL is assumed to be tested + # If port part is absent, the url is returned literally and unconditionally + # If every URL has port but none is reachable, nothing is returned + for url in `echo $@ | sed s/,/\ /g` 0; do + local host=`echo $url | cut -d \: -f 2 | sed s/^\\\/\\\///` + local port=`echo $url | cut -d \: -f 3` + [ -z "$port" ] && break + nc -z "$host" $port >/dev/null && break + done + + if [ "$url" == "0" ]; then + log_error "ERROR: none of the URLs in '$@' is reachable." + return 1 + fi + + echo $url +} + +# Run mysqld with --wsrep-recover and parse recovered position from log. +# Position will be stored in wsrep_start_position_opt global. +wsrep_start_position_opt="" +wsrep_recover_position() { + local mysqld_cmd="$@" + local euid=$(id -u) + local ret=0 + + local wr_logfile=$(mktemp $DATADIR/wsrep_recovery.XXXXXX) + + # safety checks + if [ -z $wr_logfile ]; then + log_error "WSREP: mktemp failed" + return 1 + fi + + if [ -f $wr_logfile ]; then + [ "$euid" = "0" ] && chown $user $wr_logfile + chmod 600 $wr_logfile + else + log_error "WSREP: mktemp failed" + return 1 + fi + + local wr_pidfile="$DATADIR/"`@HOSTNAME@`"-recover.pid" + + local wr_options="--log_error='$wr_logfile' --pid-file='$wr_pidfile'" + + log_notice "WSREP: Running position recovery with $wr_options" + + eval_log_error "$mysqld_cmd --wsrep_recover $wr_options" + + local rp="$(grep 'WSREP: Recovered position:' $wr_logfile)" + if [ -z "$rp" ]; then + local skipped="$(grep WSREP $wr_logfile | grep 'skipping position recovery')" + if [ -z "$skipped" ]; then + log_error "WSREP: Failed to recover position: '`cat $wr_logfile`'" + ret=1 + else + log_notice "WSREP: Position recovery skipped" + fi + else + local start_pos="$(echo $rp | sed 's/.*WSREP\:\ Recovered\ position://' \ + | sed 's/^[ \t]*//')" + log_notice "WSREP: Recovered position $start_pos" + wsrep_start_position_opt="--wsrep_start_position=$start_pos" + fi + + [ $ret -eq 0 ] && rm $wr_logfile + + return $ret +} + parse_arguments() { for arg do val=`echo "$arg" | sed -e "s;--[^=]*=;;"` @@ -236,6 +320,23 @@ parse_arguments() { --timezone=*) TZ="$val"; export TZ; ;; --flush[-_]caches) flush_caches=1 ;; --numa[-_]interleave) numa_interleave=1 ;; + --wsrep[-_]on) wsrep_on=1 ;; + --skip[-_]wsrep[-_]on) wsrep_on=0 ;; + --wsrep[-_]on=*) + if echo $val | grep -iq '\(ON\|1\)'; then + wsrep_on=1 + else + wsrep_on=0 + fi + ;; + --wsrep[-_]urls=*) wsrep_urls="$val"; ;; + --wsrep[-_]provider=*) + if test -n "$val" && test "$val" != "none" + then + wsrep_restart=1 + fi + append_arg_to_args "$arg" + ;; --help) usage ;; @@ -868,13 +969,34 @@ max_fast_restarts=5 # flag whether a usable sleep command exists have_sleep=1 +# maximum number of wsrep restarts +max_wsrep_restarts=0 + while true do rm -f "$pid_file" # Some extra safety start_time=`date +%M%S` - eval_log_error "$cmd" + # Perform wsrep position recovery if wsrep_on=1, skip otherwise. + if test $wsrep_on -eq 1 + then + # this sets wsrep_start_position_opt + wsrep_recover_position "$cmd" + + [ $? -ne 0 ] && exit 1 # + + [ -n "$wsrep_urls" ] && url=`wsrep_pick_url $wsrep_urls` # check connect address + + if [ -z "$url" ] + then + eval_log_error "$cmd $wsrep_start_position_opt" + else + eval_log_error "$cmd $wsrep_start_position_opt --wsrep_cluster_address=$url" + fi + else + eval_log_error "$cmd" + fi if [ $want_syslog -eq 0 -a ! -f "$err_log" ]; then touch "$err_log" # hypothetical: log was renamed but not @@ -944,6 +1066,20 @@ do I=`expr $I + 1` done fi + + if [ -n "$wsrep_restart" ] + then + if [ $wsrep_restart -le $max_wsrep_restarts ] + then + wsrep_restart=`expr $wsrep_restart + 1` + log_notice "WSREP: sleeping 15 seconds before restart" + sleep 15 + else + log_notice "WSREP: not restarting wsrep node automatically" + break + fi + fi + log_notice "mysqld restarted" if test -n "$CRASH_SCRIPT" then diff --git a/scripts/mysqldumpslow.sh b/scripts/mysqldumpslow.sh index c04ffad7457..d8b6158ecbe 100644 --- a/scripts/mysqldumpslow.sh +++ b/scripts/mysqldumpslow.sh @@ -27,8 +27,8 @@ use strict; use Getopt::Long; -# t=time, l=lock time, r=rows -# at, al, and ar are the corresponding averages +# t=time, l=lock time, r=rows, a=rows affected +# at, al, ar and aa are the corresponding averages my %opt = ( s => 'at', @@ -110,9 +110,11 @@ while ( defined($_ = shift @pending) or defined($_ = <>) ) { s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//; my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('',''); - s/^# Thread_id: [0-9]+\s+Schema: [^\n]+\n//; + s/^# Thread_id: [0-9]+\s+Schema: .*\s+QC_hit:.*[^\n]+\n//; s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+)\s+Rows_examined: ([0-9.]+).*\n//; my ($t, $l, $r, $e) = ($1, $2, $3, $4); + s/^# Rows_affected: ([0-9.]+).*\n//; + my ($a) = ($1); $t -= $l unless $opt{l}; @@ -156,6 +158,7 @@ while ( defined($_ = shift @pending) or defined($_ = <>) ) { $s->{l} += $l; $s->{r} += $r; $s->{e} += $e; + $s->{a} += $a; $s->{users}->{$user}++ if $user; $s->{hosts}->{$host}++ if $host; @@ -164,11 +167,12 @@ while ( defined($_ = shift @pending) or defined($_ = <>) ) { foreach (keys %stmt) { my $v = $stmt{$_} || die; - my ($c, $t, $l, $r, $e) = @{ $v }{qw(c t l r e)}; + my ($c, $t, $l, $r, $e, $a) = @{ $v }{qw(c t l r e a)}; $v->{at} = $t / $c; $v->{al} = $l / $c; $v->{ar} = $r / $c; $v->{ae} = $e / $c; + $v->{aa} = $a / $c; } my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt; @@ -177,13 +181,13 @@ my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt; foreach (@sorted) { my $v = $stmt{$_} || die; - my ($c, $t,$at, $l,$al, $r,$ar,$e, $ae) = @{ $v }{qw(c t at l al r ar e ae)}; + my ($c, $t, $at, $l, $al, $r, $ar, $e, $ae, $a, $aa) = @{ $v }{qw(c t at l al r ar e ae a aa)}; my @users = keys %{$v->{users}}; my $user = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users; my @hosts = keys %{$v->{hosts}}; my $host = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts; - printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows_sent=%.1f (%d), Rows_examined=%.1f (%d), $user\@$host\n%s\n\n", - $c, $at,$t, $al,$l, $ar,$r, $ae, $e, $_; + printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows_sent=%.1f (%d), Rows_examined=%.1f (%d), Rows_affected=%.1f (%d), $user\@$host\n%s\n\n", + $c, $at,$t, $al,$l, $ar,$r, $ae, $e, $aa, $a, $_; } sub usage { @@ -203,6 +207,7 @@ Parse and summarize the MySQL slow query log. Options are al: average lock time ar: average rows sent at: average query time + aa: average rows affected c: count l: lock time r: rows sent diff --git a/scripts/mytop.sh b/scripts/mytop.sh index 1cf1c5313b4..17a87e9efd2 100644 --- a/scripts/mytop.sh +++ b/scripts/mytop.sh @@ -6,7 +6,7 @@ =head1 NAME -mytop - display MySQL server performance info like `top' +mytop - display MariaDB server performance info like `top' =cut @@ -256,7 +256,7 @@ my $dbh = DBI->connect($dsn, $config{user}, $config{pass}, if (not ref $dbh) { my $Error = <<EODIE -Cannot connect to MySQL server. Please check the: +Cannot connect to MariaDB server. Please check the: * database you specified "$config{db}" (default is "test") * username you specified "$config{user}" (default is "root") @@ -1885,12 +1885,11 @@ pick up Term::ReadKey here: http://search.cpan.org/search?dist=TermReadKey -And you obviously need access to a MySQL server (version 3.22.x or -3.23.x) with the necessary security to run the I<SHOW PROCESSLIST> and -I<SHOW STATUS> commands. +And you obviously need access to a MariaDB server with the necessary +security to run the I<SHOW PROCESSLIST> and I<SHOW STATUS> commands. If you are a Windows user, using ActiveState's Perl, you can use PPM -(the Perl Package Manager) to install the MySQL and Term::ReadKey +(the Perl Package Manager) to install the MariaDB/MySQL and Term::ReadKey modules. =head2 Optional Color Support @@ -1942,24 +1941,24 @@ B<mytop> was inspired by the system monitoring tool B<top>. I routinely use B<top> on Linux, FreeBSD, and Solaris. You are likely to notice features from each of them here. -B<mytop> will connect to a MySQL server and periodically run the +B<mytop> will connect to a MariaDB server and periodically run the I<SHOW PROCESSLIST> and I<SHOW STATUS> commands and attempt to summarize the information from them in a useful format. =head2 The Display The B<mytop> display screen is really broken into two parts. The top 4 -lines (header) contain summary information about your MySQL +lines (header) contain summary information about your MariaDB server. For example, you might see something like: -MySQL on localhost (4.0.13-log) up 1+11:13:00 [23:29:11] +MariaDB on localhost (10.0.13-log) up 1+11:13:00 [23:29:11] Queries: 19.3M qps: 160 Slow: 1.0 Se/In/Up/De(%): 00/80/03/17 qps now: 219 Slow qps: 0.0 Threads: 1 ( 1/ 16) 00/74/00/25 Key Efficiency: 99.3% Bps in/out: 30.5k/162.8 Now in/out: 32.7k/ 3.3k The first line identifies the hostname of the server (localhost) and -the version of MySQL it is running. The right had side shows the -uptime of the MySQL server process in days+hours:minutes:seconds +the version of MariaDB it is running. The right had side shows the +uptime of the MariaDB server process in days+hours:minutes:seconds format (much like FreeBSD's top) as well as the current time. The second line displays the total number of queries the server has @@ -1973,7 +1972,7 @@ on the previous line). And the fourth line displays key buffer efficiency (how often keys are read from the buffer rather than disk) and the number of bytes that -MySQL has sent and received, both over all and in the last cycle. +MariaDB has sent and received, both over all and in the last cycle. You can toggle the header by hitting B<h> when running B<mytop>. @@ -2019,21 +2018,21 @@ have two dashes `--'. Short arguments only have one '-'. =item B<-u> or B<-user> username -Username to use when logging in to the MySQL server. Default: ``root''. +Username to use when logging in to the MariaDB server. Default: ``root''. =item B<-p> or B<-pass> or B<-password> password -Password to use when logging in to the MySQL server. Default: none. +Password to use when logging in to the MariaDB server. Default: none. =item B<-h> or B<--host> hostname[:port] -Hostname of the MySQL server. The hostname may be followed by an +Hostname of the MariaDB server. The hostname may be followed by an option port number. Note that the port is specified separate from the host when using a config file. Default: ``localhost''. =item B<--port> or B<-P> port -If you're running MySQL on a non-standard port, use this to specify +If you're running MariaDB on a non-standard port, use this to specify the port number. Default: 3306. =item B<-s> or B<--delay> seconds @@ -2051,15 +2050,15 @@ In batch mode, mytop runs only once, does not clear the screen, and places no limit on the number of lines it will print. This is suitable for running periodically (perhaps from cron) to capture the information into a file for later viewing. You might use batch mode in -a CGI script to occasionally display your MySQL server status on the +a CGI script to occasionally display your MariaDB server status on the web. Default: unset. =item B<-S> or B<--socket> /path/to/socket -If you're running B<mytop> on the same host as MySQL, you may wish to -have it use the MySQL socket directly rather than a standard TCP/IP +If you're running B<mytop> on the same host as MariaDB, you may wish to +have it use the MariaDB socket directly rather than a standard TCP/IP connection. If you do,just specify one. Note that specifying a socket will make B<mytop> ignore any host @@ -2105,7 +2104,7 @@ Default: noprompt. =item B<--resolve> -If you have skip-resolve set on MySQL (to keep it from doing a reverse +If you have skip-resolve set on MariaDB (to keep it from doing a reverse DNS lookup on each inbound connection), mytop can replace IP addresses with hostnames but toggling this option. diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh new file mode 100644 index 00000000000..5f84a00c214 --- /dev/null +++ b/scripts/wsrep_sst_common.sh @@ -0,0 +1,171 @@ +# Copyright (C) 2012-2014 Codership Oy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston +# MA 02110-1301 USA. + +# This is a common command line parser to be sourced by other SST scripts + +set -u + +WSREP_SST_OPT_BYPASS=0 +WSREP_SST_OPT_BINLOG="" +WSREP_SST_OPT_DATA="" +WSREP_SST_OPT_AUTH="" +WSREP_SST_OPT_DEFAULT="" +WSREP_SST_OPT_EXTRA_DEFAULT="" + + +while [ $# -gt 0 ]; do +case "$1" in + '--address') + readonly WSREP_SST_OPT_ADDR="$2" + shift + ;; + '--auth') + WSREP_SST_OPT_AUTH="$2" + shift + ;; + '--bypass') + WSREP_SST_OPT_BYPASS=1 + ;; + '--datadir') + readonly WSREP_SST_OPT_DATA="$2" + shift + ;; + '--defaults-file') + readonly WSREP_SST_OPT_DEFAULT="$1=$2" + shift + ;; + '--defaults-extra-file') + readonly WSREP_SST_OPT_EXTRA_DEFAULT="$1=$2" + shift + ;; + '--host') + readonly WSREP_SST_OPT_HOST="$2" + shift + ;; + '--local-port') + readonly WSREP_SST_OPT_LPORT="$2" + shift + ;; + '--parent') + readonly WSREP_SST_OPT_PARENT="$2" + shift + ;; + '--password') + WSREP_SST_OPT_PSWD="$2" + shift + ;; + '--port') + readonly WSREP_SST_OPT_PORT="$2" + shift + ;; + '--role') + readonly WSREP_SST_OPT_ROLE="$2" + shift + ;; + '--socket') + readonly WSREP_SST_OPT_SOCKET="$2" + shift + ;; + '--user') + WSREP_SST_OPT_USER="$2" + shift + ;; + '--gtid') + readonly WSREP_SST_OPT_GTID="$2" + shift + ;; + '--binlog') + WSREP_SST_OPT_BINLOG="$2" + shift + ;; + '--gtid-domain-id') + readonly WSREP_SST_OPT_GTID_DOMAIN_ID="$2" + shift + ;; + *) # must be command + # usage + # exit 1 + ;; +esac +shift +done +readonly WSREP_SST_OPT_BYPASS +readonly WSREP_SST_OPT_BINLOG + +readonly WSREP_SST_OPT_CONF="$WSREP_SST_OPT_DEFAULT $WSREP_SST_OPT_EXTRA_DEFAULT" +readonly my_print_defaults="my_print_defaults $WSREP_SST_OPT_CONF" + +# State Snapshot Transfer authentication password was displayed in the ps output. Bug fixed #1200727. +if $my_print_defaults sst | grep -q "wsrep_sst_auth";then + if [ -z "$WSREP_SST_OPT_AUTH" -o "$WSREP_SST_OPT_AUTH" = "(null)" ];then + WSREP_SST_OPT_AUTH=$($my_print_defaults sst | grep -- "--wsrep_sst_auth" | cut -d= -f2) + fi +fi + +if [ -n "${WSREP_SST_OPT_DATA:-}" ] +then + SST_PROGRESS_FILE="$WSREP_SST_OPT_DATA/sst_in_progress" +else + SST_PROGRESS_FILE="" +fi + + +wsrep_log() +{ + # echo everything to stderr so that it gets into common error log + # deliberately made to look different from the rest of the log + local readonly tst="$(date +%Y%m%d\ %H:%M:%S.%N | cut -b -21)" + echo "WSREP_SST: $* ($tst)" >&2 +} + +wsrep_log_error() +{ + wsrep_log "[ERROR] $*" +} + +wsrep_log_info() +{ + wsrep_log "[INFO] $*" +} + +wsrep_cleanup_progress_file() +{ + [ -n "$SST_PROGRESS_FILE" ] && rm -f "$SST_PROGRESS_FILE" 2>/dev/null +} + +wsrep_check_program() +{ + local prog=$1 + + if ! which $prog >/dev/null + then + echo "'$prog' not found in PATH" + return 2 # no such file or directory + fi +} + +wsrep_check_programs() +{ + local ret=0 + + while [ $# -gt 0 ] + do + wsrep_check_program $1 || ret=$? + shift + done + + return $ret +} diff --git a/scripts/wsrep_sst_mysqldump.sh b/scripts/wsrep_sst_mysqldump.sh new file mode 100644 index 00000000000..d7fb6756663 --- /dev/null +++ b/scripts/wsrep_sst_mysqldump.sh @@ -0,0 +1,178 @@ +#!/bin/bash -e +# Copyright (C) 2009 Codership Oy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston +# MA 02110-1301 USA. + +# This is a reference script for mysqldump-based state snapshot tansfer + +# This variable is not used in mysqldump sst, so better initialize it +# to avoid shell's "parameter not set" message. +WSREP_SST_OPT_CONF="" + +. $(dirname $0)/wsrep_sst_common +PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin + +EINVAL=22 + +local_ip() +{ + [ "$1" = "127.0.0.1" ] && return 0 + [ "$1" = "localhost" ] && return 0 + [ "$1" = "$(hostname -s)" ] && return 0 + [ "$1" = "$(hostname -f)" ] && return 0 + [ "$1" = "$(hostname -d)" ] && return 0 + + # Now if ip program is not found in the path, we can't return 0 since + # it would block any address. Thankfully grep should fail in this case + ip route get "$1" | grep local >/dev/null && return 0 + + return 1 +} + +if test -z "$WSREP_SST_OPT_USER"; then wsrep_log_error "USER cannot be nil"; exit $EINVAL; fi +if test -z "$WSREP_SST_OPT_HOST"; then wsrep_log_error "HOST cannot be nil"; exit $EINVAL; fi +if test -z "$WSREP_SST_OPT_PORT"; then wsrep_log_error "PORT cannot be nil"; exit $EINVAL; fi +if test -z "$WSREP_SST_OPT_LPORT"; then wsrep_log_error "LPORT cannot be nil"; exit $EINVAL; fi +if test -z "$WSREP_SST_OPT_SOCKET";then wsrep_log_error "SOCKET cannot be nil";exit $EINVAL; fi +if test -z "$WSREP_SST_OPT_GTID"; then wsrep_log_error "GTID cannot be nil"; exit $EINVAL; fi + +if local_ip $WSREP_SST_OPT_HOST && \ + [ "$WSREP_SST_OPT_PORT" = "$WSREP_SST_OPT_LPORT" ] +then + wsrep_log_error \ + "destination address '$WSREP_SST_OPT_HOST:$WSREP_SST_OPT_PORT' matches source address." + exit $EINVAL +fi + +# Check client version +if ! mysql --version | grep 'Distrib 10' >/dev/null +then + mysql --version >&2 + wsrep_log_error "this operation requires MySQL client version 10 or newer" + exit $EINVAL +fi + +# For Bug:1293798 +if [ -z "$WSREP_SST_OPT_PSWD" -a -n "$WSREP_SST_OPT_AUTH" ]; then + WSREP_SST_OPT_USER=$(echo $WSREP_SST_OPT_AUTH | cut -d: -f1) + WSREP_SST_OPT_PSWD=$(echo $WSREP_SST_OPT_AUTH | cut -d: -f2) +fi +AUTH="-u$WSREP_SST_OPT_USER" +if test -n "$WSREP_SST_OPT_PSWD"; then AUTH="$AUTH -p$WSREP_SST_OPT_PSWD"; fi + +STOP_WSREP="SET wsrep_on=OFF;" + +# mysqldump cannot restore CSV tables, fix this issue +CSV_TABLES_FIX=" +set sql_mode=''; + +USE mysql; + +SET @cond = (SELECT (SUPPORT = 'YES' or SUPPORT = 'DEFAULT') FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'csv'); + +SET @stmt = IF (@cond = '1', 'CREATE TABLE IF NOT EXISTS general_log ( event_time timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), user_host mediumtext NOT NULL, thread_id bigint(21) unsigned NOT NULL, server_id int(10) unsigned NOT NULL, command_type varchar(64) NOT NULL, argument mediumtext NOT NULL) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT=\"General log\"', 'SET @dummy = 0'); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DROP PREPARE stmt; + +SET @stmt = IF (@cond = '1', 'CREATE TABLE IF NOT EXISTS slow_log ( start_time timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), user_host mediumtext NOT NULL, query_time time(6) NOT NULL, lock_time time(6) NOT NULL, rows_sent int(11) NOT NULL, rows_examined int(11) NOT NULL, db varchar(512) NOT NULL, last_insert_id int(11) NOT NULL, insert_id int(11) NOT NULL, server_id int(10) unsigned NOT NULL, sql_text mediumtext NOT NULL, thread_id bigint(21) unsigned NOT NULL) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT=\"Slow log\"', 'SET @dummy = 0'); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DROP PREPARE stmt;" + +SET_START_POSITION="SET GLOBAL wsrep_start_position='$WSREP_SST_OPT_GTID';" + +SET_WSREP_GTID_DOMAIN_ID="" +if [ -n $WSREP_SST_OPT_GTID_DOMAIN_ID ] +then + SET_WSREP_GTID_DOMAIN_ID=" + SET @val = (SELECT GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME = 'WSREP_GTID_STRICT_MODE' AND GLOBAL_VALUE > 0); + SET @stmt = IF (@val IS NOT NULL, 'SET GLOBAL WSREP_GTID_DOMAIN_ID=$WSREP_SST_OPT_GTID_DOMAIN_ID', 'SET @dummy = 0'); + PREPARE stmt FROM @stmt; + EXECUTE stmt; + DROP PREPARE stmt;" +fi + +# Retrieve the donor's @@global.gtid_binlog_state. +GTID_BINLOG_STATE=$(echo "SHOW GLOBAL VARIABLES LIKE 'gtid_binlog_state'" |\ +mysql $AUTH -S$WSREP_SST_OPT_SOCKET --disable-reconnect --connect_timeout=10 |\ +tail -1 | awk -F ' ' '{ print $2 }') + +MYSQL="mysql $AUTH -h$WSREP_SST_OPT_HOST -P$WSREP_SST_OPT_PORT "\ +"--disable-reconnect --connect_timeout=10" + +# Check if binary logging is enabled on the joiner node. +# Note: SELECT cannot be used at this point. +LOG_BIN=$(echo "SHOW VARIABLES LIKE 'log_bin'" | $MYSQL |\ +tail -1 | awk -F ' ' '{ print $2 }') + +# Check the joiner node's server version. +SERVER_VERSION=$(echo "SHOW VARIABLES LIKE 'version'" | $MYSQL |\ +tail -1 | awk -F ' ' '{ print $2 }') + +RESET_MASTER="" +SET_GTID_BINLOG_STATE="" +SQL_LOG_BIN_OFF="" + +# Safety check +if echo $SERVER_VERSION | grep '^10.1' > /dev/null +then + # If binary logging is enabled on the joiner node, we need to copy donor's + # gtid_binlog_state to joiner. In order to do that, a RESET MASTER must be + # executed to erase binary logs (if any). Binary logging should also be + # turned off for the session so that gtid state does not get altered while + # the dump gets replayed on joiner. + if [[ "$LOG_BIN" == 'ON' ]]; then + RESET_MASTER="RESET MASTER;" + SET_GTID_BINLOG_STATE="SET @@global.gtid_binlog_state='$GTID_BINLOG_STATE';" + SQL_LOG_BIN_OFF="SET @@session.sql_log_bin=OFF;" + fi +fi + +# NOTE: we don't use --routines here because we're dumping mysql.proc table +MYSQLDUMP="mysqldump $AUTH -S$WSREP_SST_OPT_SOCKET \ +--add-drop-database --add-drop-table --skip-add-locks --create-options \ +--disable-keys --extended-insert --skip-lock-tables --quick --set-charset \ +--skip-comments --flush-privileges --all-databases" + +# need to disable logging when loading the dump +# reason is that dump contains ALTER TABLE for log tables, and +# this causes an error if logging is enabled +GENERAL_LOG_OPT=`$MYSQL --skip-column-names -e"$STOP_WSREP SELECT @@GENERAL_LOG"` +SLOW_LOG_OPT=`$MYSQL --skip-column-names -e"$STOP_WSREP SELECT @@SLOW_QUERY_LOG"` +$MYSQL -e"$STOP_WSREP SET GLOBAL GENERAL_LOG=OFF" +$MYSQL -e"$STOP_WSREP SET GLOBAL SLOW_QUERY_LOG=OFF" + +# commands to restore log settings +RESTORE_GENERAL_LOG="SET GLOBAL GENERAL_LOG=$GENERAL_LOG_OPT;" +RESTORE_SLOW_QUERY_LOG="SET GLOBAL SLOW_QUERY_LOG=$SLOW_LOG_OPT;" + + +if [ $WSREP_SST_OPT_BYPASS -eq 0 ] +then + (echo $STOP_WSREP && echo $RESET_MASTER && \ + echo $SET_GTID_BINLOG_STATE && echo $SQL_LOG_BIN_OFF && \ + echo $STOP_WSREP && $MYSQLDUMP && echo $CSV_TABLES_FIX && \ + echo $RESTORE_GENERAL_LOG && echo $RESTORE_SLOW_QUERY_LOG && \ + echo $SET_START_POSITION && echo $SET_WSREP_GTID_DOMAIN_ID \ + || echo "SST failed to complete;") | $MYSQL +else + wsrep_log_info "Bypassing state dump." + echo $SET_START_POSITION | $MYSQL +fi + +# diff --git a/scripts/wsrep_sst_rsync.sh b/scripts/wsrep_sst_rsync.sh new file mode 100644 index 00000000000..576ce212261 --- /dev/null +++ b/scripts/wsrep_sst_rsync.sh @@ -0,0 +1,346 @@ +#!/bin/bash -ue + +# Copyright (C) 2010-2014 Codership Oy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston +# MA 02110-1301 USA. + +# This is a reference script for rsync-based state snapshot tansfer + +RSYNC_PID= +RSYNC_CONF= +OS=$(uname) +[ "$OS" == "Darwin" ] && export -n LD_LIBRARY_PATH + +# Setting the path for lsof on CentOS +export PATH="/usr/sbin:/sbin:$PATH" + +. $(dirname $0)/wsrep_sst_common + +wsrep_check_programs rsync + +cleanup_joiner() +{ + wsrep_log_info "Joiner cleanup." + local PID=$(cat "$RSYNC_PID" 2>/dev/null || echo 0) + [ "0" != "$PID" ] && kill $PID && sleep 0.5 && kill -9 $PID >/dev/null 2>&1 \ + || : + rm -rf "$RSYNC_CONF" + rm -rf "$MAGIC_FILE" + rm -rf "$RSYNC_PID" + wsrep_log_info "Joiner cleanup done." + if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then + wsrep_cleanup_progress_file + fi +} + +check_pid() +{ + local pid_file=$1 + [ -r "$pid_file" ] && ps -p $(cat $pid_file) >/dev/null 2>&1 +} + +check_pid_and_port() +{ + local pid_file=$1 + local rsync_pid=$2 + local rsync_port=$3 + + if ! which lsof > /dev/null; then + wsrep_log_error "lsof tool not found in PATH! Make sure you have it installed." + exit 2 # ENOENT + fi + + local port_info=$(lsof -i :$rsync_port -Pn 2>/dev/null | \ + grep "(LISTEN)") + local is_rsync=$(echo $port_info | \ + grep -w '^rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null) + + if [ -n "$port_info" -a -z "$is_rsync" ]; then + wsrep_log_error "rsync daemon port '$rsync_port' has been taken" + exit 16 # EBUSY + fi + check_pid $pid_file && \ + [ -n "$port_info" ] && [ -n "$is_rsync" ] && \ + [ $(cat $pid_file) -eq $rsync_pid ] +} + +MAGIC_FILE="$WSREP_SST_OPT_DATA/rsync_sst_complete" +rm -rf "$MAGIC_FILE" + +BINLOG_TAR_FILE="$WSREP_SST_OPT_DATA/wsrep_sst_binlog.tar" +BINLOG_N_FILES=1 +rm -f "$BINLOG_TAR_FILE" || : + +if ! [ -z $WSREP_SST_OPT_BINLOG ] +then + BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG) + BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG) +fi + +WSREP_LOG_DIR=${WSREP_LOG_DIR:-""} +# if WSREP_LOG_DIR env. variable is not set, try to get it from my.cnf +if [ -z "$WSREP_LOG_DIR" ]; then + WSREP_LOG_DIR=$($my_print_defaults --mysqld \ + | grep -- '--innodb[-_]log[-_]group[-_]home[-_]dir=' \ + | cut -b 29- ) +fi + +if [ -n "$WSREP_LOG_DIR" ]; then + # handle both relative and absolute paths + WSREP_LOG_DIR=$(cd $WSREP_SST_OPT_DATA; mkdir -p "$WSREP_LOG_DIR"; cd $WSREP_LOG_DIR; pwd -P) +else + # default to datadir + WSREP_LOG_DIR=$(cd $WSREP_SST_OPT_DATA; pwd -P) +fi + +# Old filter - include everything except selected +# FILTER=(--exclude '*.err' --exclude '*.pid' --exclude '*.sock' \ +# --exclude '*.conf' --exclude core --exclude 'galera.*' \ +# --exclude grastate.txt --exclude '*.pem' \ +# --exclude '*.[0-9][0-9][0-9][0-9][0-9][0-9]' --exclude '*.index') + +# New filter - exclude everything except dirs (schemas) and innodb files +FILTER=(-f '- /lost+found' -f '- /.fseventsd' -f '- /.Trashes' + -f '+ /wsrep_sst_binlog.tar' -f '+ /ib_lru_dump' -f '+ /ibdata*' -f '+ /*/' -f '- /*') + +if [ "$WSREP_SST_OPT_ROLE" = "donor" ] +then + + if [ $WSREP_SST_OPT_BYPASS -eq 0 ] + then + + FLUSHED="$WSREP_SST_OPT_DATA/tables_flushed" + rm -rf "$FLUSHED" + + # Use deltaxfer only for WAN + inv=$(basename $0) + [ "$inv" = "wsrep_sst_rsync_wan" ] && WHOLE_FILE_OPT="" \ + || WHOLE_FILE_OPT="--whole-file" + + echo "flush tables" + + # Wait for : + # (a) tables to be flushed, and + # (b) state ID & wsrep_gtid_domain_id to be written to the file. + while [ ! -r "$FLUSHED" ] && ! grep -q ':' "$FLUSHED" >/dev/null 2>&1 + do + sleep 0.2 + done + + STATE="$(cat $FLUSHED)" + rm -rf "$FLUSHED" + + sync + + if ! [ -z $WSREP_SST_OPT_BINLOG ] + then + # Prepare binlog files + pushd $BINLOG_DIRNAME &> /dev/null + binlog_files_full=$(tail -n $BINLOG_N_FILES ${BINLOG_FILENAME}.index) + binlog_files="" + for ii in $binlog_files_full + do + binlog_files="$binlog_files $(basename $ii)" + done + if ! [ -z "$binlog_files" ] + then + wsrep_log_info "Preparing binlog files for transfer:" + tar -cvf $BINLOG_TAR_FILE $binlog_files >&2 + fi + popd &> /dev/null + fi + + # first, the normal directories, so that we can detect incompatible protocol + RC=0 + rsync --owner --group --perms --links --specials \ + --ignore-times --inplace --dirs --delete --quiet \ + $WHOLE_FILE_OPT "${FILTER[@]}" "$WSREP_SST_OPT_DATA/" \ + rsync://$WSREP_SST_OPT_ADDR >&2 || RC=$? + + if [ "$RC" -ne 0 ]; then + wsrep_log_error "rsync returned code $RC:" + + case $RC in + 12) RC=71 # EPROTO + wsrep_log_error \ + "rsync server on the other end has incompatible protocol. " \ + "Make sure you have the same version of rsync on all nodes." + ;; + 22) RC=12 # ENOMEM + ;; + *) RC=255 # unknown error + ;; + esac + exit $RC + fi + + # second, we transfer InnoDB log files + rsync --owner --group --perms --links --specials \ + --ignore-times --inplace --dirs --delete --quiet \ + $WHOLE_FILE_OPT -f '+ /ib_logfile[0-9]*' -f '- **' "$WSREP_LOG_DIR/" \ + rsync://$WSREP_SST_OPT_ADDR-log_dir >&2 || RC=$? + + if [ $RC -ne 0 ]; then + wsrep_log_error "rsync innodb_log_group_home_dir returned code $RC:" + exit 255 # unknown error + fi + + # then, we parallelize the transfer of database directories, use . so that pathconcatenation works + pushd "$WSREP_SST_OPT_DATA" >/dev/null + + count=1 + [ "$OS" == "Linux" ] && count=$(grep -c processor /proc/cpuinfo) + [ "$OS" == "Darwin" -o "$OS" == "FreeBSD" ] && count=$(sysctl -n hw.ncpu) + + find . -maxdepth 1 -mindepth 1 -type d -print0 | xargs -I{} -0 -P $count \ + rsync --owner --group --perms --links --specials \ + --ignore-times --inplace --recursive --delete --quiet \ + $WHOLE_FILE_OPT --exclude '*/ib_logfile*' "$WSREP_SST_OPT_DATA"/{}/ \ + rsync://$WSREP_SST_OPT_ADDR/{} >&2 || RC=$? + + popd >/dev/null + + if [ $RC -ne 0 ]; then + wsrep_log_error "find/rsync returned code $RC:" + exit 255 # unknown error + fi + + else # BYPASS + wsrep_log_info "Bypassing state dump." + + # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id + # (separated by a space). + STATE="$WSREP_SST_OPT_GTID $WSREP_SST_OPT_GTID_DOMAIN_ID" + fi + + echo "continue" # now server can resume updating data + + echo "$STATE" > "$MAGIC_FILE" + rsync --archive --quiet --checksum "$MAGIC_FILE" rsync://$WSREP_SST_OPT_ADDR + + echo "done $STATE" + +elif [ "$WSREP_SST_OPT_ROLE" = "joiner" ] +then + wsrep_check_programs lsof + + touch $SST_PROGRESS_FILE + MYSQLD_PID=$WSREP_SST_OPT_PARENT + + MODULE="rsync_sst" + + RSYNC_PID="$WSREP_SST_OPT_DATA/$MODULE.pid" + + if check_pid $RSYNC_PID + then + wsrep_log_error "rsync daemon already running." + exit 114 # EALREADY + fi + rm -rf "$RSYNC_PID" + + ADDR=$WSREP_SST_OPT_ADDR + RSYNC_PORT=$(echo $ADDR | awk -F ':' '{ print $2 }') + if [ -z "$RSYNC_PORT" ] + then + RSYNC_PORT=4444 + ADDR="$(echo $ADDR | awk -F ':' '{ print $1 }'):$RSYNC_PORT" + fi + + trap "exit 32" HUP PIPE + trap "exit 3" INT TERM ABRT + trap cleanup_joiner EXIT + + RSYNC_CONF="$WSREP_SST_OPT_DATA/$MODULE.conf" + + if [ -n "${MYSQL_TMP_DIR:-}" ] ; then + SILENT="log file = $MYSQL_TMP_DIR/rsynd.log" + else + SILENT="" + fi + +cat << EOF > "$RSYNC_CONF" +pid file = $RSYNC_PID +use chroot = no +read only = no +timeout = 300 +$SILENT +[$MODULE] + path = $WSREP_SST_OPT_DATA +[$MODULE-log_dir] + path = $WSREP_LOG_DIR +EOF + +# rm -rf "$DATA"/ib_logfile* # we don't want old logs around + + # listen at all interfaces (for firewalled setups) + rsync --daemon --no-detach --port $RSYNC_PORT --config "$RSYNC_CONF" & + RSYNC_REAL_PID=$! + + until check_pid_and_port $RSYNC_PID $RSYNC_REAL_PID $RSYNC_PORT + do + sleep 0.2 + done + + echo "ready $ADDR/$MODULE" + + # wait for SST to complete by monitoring magic file + while [ ! -r "$MAGIC_FILE" ] && check_pid "$RSYNC_PID" && \ + ps -p $MYSQLD_PID >/dev/null + do + sleep 1 + done + + if ! ps -p $MYSQLD_PID >/dev/null + then + wsrep_log_error \ + "Parent mysqld process (PID:$MYSQLD_PID) terminated unexpectedly." + exit 32 + fi + + if ! [ -z $WSREP_SST_OPT_BINLOG ] + then + + pushd $BINLOG_DIRNAME &> /dev/null + if [ -f $BINLOG_TAR_FILE ] + then + # Clean up old binlog files first + rm -f ${BINLOG_FILENAME}.* + wsrep_log_info "Extracting binlog files:" + tar -xvf $BINLOG_TAR_FILE >&2 + for ii in $(ls -1 ${BINLOG_FILENAME}.*) + do + echo ${BINLOG_DIRNAME}/${ii} >> ${BINLOG_FILENAME}.index + done + fi + popd &> /dev/null + fi + if [ -r "$MAGIC_FILE" ] + then + # UUID:seqno & wsrep_gtid_domain_id is received here. + cat "$MAGIC_FILE" # Output : UUID:seqno wsrep_gtid_domain_id + else + # this message should cause joiner to abort + echo "rsync process ended without creating '$MAGIC_FILE'" + fi + wsrep_cleanup_progress_file +# cleanup_joiner +else + wsrep_log_error "Unrecognized role: '$WSREP_SST_OPT_ROLE'" + exit 22 # EINVAL +fi + +rm -f $BINLOG_TAR_FILE || : + +exit 0 diff --git a/scripts/wsrep_sst_xtrabackup-v2.sh b/scripts/wsrep_sst_xtrabackup-v2.sh new file mode 100644 index 00000000000..3b4efb2422f --- /dev/null +++ b/scripts/wsrep_sst_xtrabackup-v2.sh @@ -0,0 +1,935 @@ +#!/bin/bash -ue +# Copyright (C) 2013 Percona Inc +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston +# MA 02110-1301 USA. + +# Documentation: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html +# Make sure to read that before proceeding! + + + + +. $(dirname $0)/wsrep_sst_common + +ealgo="" +ekey="" +ekeyfile="" +encrypt=0 +nproc=1 +ecode=0 +XTRABACKUP_PID="" +SST_PORT="" +REMOTEIP="" +tcert="" +tpem="" +tkey="" +sockopt="" +progress="" +ttime=0 +totime=0 +lsn="" +incremental=0 +ecmd="" +rlimit="" +# Initially +stagemsg="${WSREP_SST_OPT_ROLE}" +cpat="" +speciald=0 +ib_home_dir="" +ib_log_dir="" + +sfmt="tar" +strmcmd="" +tfmt="" +tcmd="" +rebuild=0 +rebuildcmd="" +payload=0 +pvformat="-F '%N => Rate:%r Avg:%a Elapsed:%t %e Bytes: %b %p' " +pvopts="-f -i 10 -N $WSREP_SST_OPT_ROLE " +STATDIR="" +uextra=0 +disver="" + +tmpopts="" +itmpdir="" +xtmpdir="" + +scomp="" +sdecomp="" + +if which pv &>/dev/null && pv --help | grep -q FORMAT;then + pvopts+=$pvformat +fi +pcmd="pv $pvopts" +declare -a RC + +INNOBACKUPEX_BIN=innobackupex +readonly AUTH=(${WSREP_SST_OPT_AUTH//:/ }) +DATA="${WSREP_SST_OPT_DATA}" +INFO_FILE="xtrabackup_galera_info" +IST_FILE="xtrabackup_ist" +MAGIC_FILE="${DATA}/${INFO_FILE}" + +# Setting the path for ss and ip +export PATH="/usr/sbin:/sbin:$PATH" + +timeit(){ + local stage=$1 + shift + local cmd="$@" + local x1 x2 took extcode + + if [[ $ttime -eq 1 ]];then + x1=$(date +%s) + wsrep_log_info "Evaluating $cmd" + eval "$cmd" + extcode=$? + x2=$(date +%s) + took=$(( x2-x1 )) + wsrep_log_info "NOTE: $stage took $took seconds" + totime=$(( totime+took )) + else + wsrep_log_info "Evaluating $cmd" + eval "$cmd" + extcode=$? + fi + return $extcode +} + +get_keys() +{ + # $encrypt -eq 1 is for internal purposes only + if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then + return + fi + + if [[ $encrypt -eq 0 ]];then + if $my_print_defaults xtrabackup | grep -q encrypt;then + wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html " + fi + return + fi + + if [[ $sfmt == 'tar' ]];then + wsrep_log_info "NOTE: Xtrabackup-based encryption - encrypt=1 - cannot be enabled with tar format" + encrypt=-1 + return + fi + + wsrep_log_info "Xtrabackup based encryption enabled in my.cnf - Supported only from Xtrabackup 2.1.4" + + if [[ -z $ealgo ]];then + wsrep_log_error "FATAL: Encryption algorithm empty from my.cnf, bailing out" + exit 3 + fi + + if [[ -z $ekey && ! -r $ekeyfile ]];then + wsrep_log_error "FATAL: Either key or keyfile must be readable" + exit 3 + fi + + if [[ -z $ekey ]];then + ecmd="xbcrypt --encrypt-algo=$ealgo --encrypt-key-file=$ekeyfile" + else + ecmd="xbcrypt --encrypt-algo=$ealgo --encrypt-key=$ekey" + fi + + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + ecmd+=" -d" + fi + + stagemsg+="-XB-Encrypted" +} + +get_transfer() +{ + if [[ -z $SST_PORT ]];then + TSST_PORT=4444 + else + TSST_PORT=$SST_PORT + fi + + if [[ $tfmt == 'nc' ]];then + if [[ ! -x `which nc` ]];then + wsrep_log_error "nc(netcat) not found in path: $PATH" + exit 2 + fi + wsrep_log_info "Using netcat as streamer" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + tcmd="nc -dl ${TSST_PORT}" + else + tcmd="nc ${REMOTEIP} ${TSST_PORT}" + fi + else + tfmt='socat' + wsrep_log_info "Using socat as streamer" + if [[ ! -x `which socat` ]];then + wsrep_log_error "socat not found in path: $PATH" + exit 2 + fi + + if [[ $encrypt -eq 2 || $encrypt -eq 3 ]] && ! socat -V | grep -q WITH_OPENSSL;then + wsrep_log_info "NOTE: socat is not openssl enabled, falling back to plain transfer" + encrypt=-1 + fi + + if [[ $encrypt -eq 2 ]];then + wsrep_log_info "Using openssl based encryption with socat: with crt and pem" + if [[ -z $tpem || -z $tcert ]];then + wsrep_log_error "Both PEM and CRT files required" + exit 22 + fi + stagemsg+="-OpenSSL-Encrypted-2" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + wsrep_log_info "Decrypting with PEM $tpem, CA: $tcert" + tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=$tpem,cafile=${tcert}${sockopt} stdio" + else + wsrep_log_info "Encrypting with PEM $tpem, CA: $tcert" + tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=$tpem,cafile=${tcert}${sockopt}" + fi + elif [[ $encrypt -eq 3 ]];then + wsrep_log_info "Using openssl based encryption with socat: with key and crt" + if [[ -z $tpem || -z $tkey ]];then + wsrep_log_error "Both certificate and key files required" + exit 22 + fi + stagemsg+="-OpenSSL-Encrypted-3" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + wsrep_log_info "Decrypting with certificate $tpem, key $tkey" + tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=$tpem,key=${tkey},verify=0${sockopt} stdio" + else + wsrep_log_info "Encrypting with certificate $tpem, key $tkey" + tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=$tpem,key=${tkey},verify=0${sockopt}" + fi + + else + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio" + else + tcmd="socat -u stdio TCP:${REMOTEIP}:${TSST_PORT}${sockopt}" + fi + fi + fi + +} + +parse_cnf() +{ + local group=$1 + local var=$2 + reval=$($my_print_defaults $group | awk -F= '{if ($1 ~ /_/) { gsub(/_/,"-",$1); print $1"="$2 } else { print $0 }}' | grep -- "--$var=" | cut -d= -f2-) + if [[ -z $reval ]];then + [[ -n $3 ]] && reval=$3 + fi + echo $reval +} + +get_footprint() +{ + pushd $WSREP_SST_OPT_DATA 1>/dev/null + payload=$(find . -regex '.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' -type f -print0 | du --files0-from=- --block-size=1 -c | awk 'END { print $1 }') + if $my_print_defaults xtrabackup | grep -q -- "--compress";then + # QuickLZ has around 50% compression ratio + # When compression/compaction used, the progress is only an approximate. + payload=$(( payload*1/2 )) + fi + popd 1>/dev/null + pcmd+=" -s $payload" + adjust_progress +} + +adjust_progress() +{ + if [[ -n $progress && $progress != '1' ]];then + if [[ -e $progress ]];then + pcmd+=" 2>>$progress" + else + pcmd+=" 2>$progress" + fi + elif [[ -z $progress && -n $rlimit ]];then + # When rlimit is non-zero + pcmd="pv -q" + fi + + if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then + wsrep_log_info "Rate-limiting SST to $rlimit" + pcmd+=" -L \$rlimit" + fi +} + +read_cnf() +{ + sfmt=$(parse_cnf sst streamfmt "xbstream") + tfmt=$(parse_cnf sst transferfmt "socat") + tcert=$(parse_cnf sst tca "") + tpem=$(parse_cnf sst tcert "") + tkey=$(parse_cnf sst tkey "") + encrypt=$(parse_cnf sst encrypt 0) + sockopt=$(parse_cnf sst sockopt "") + progress=$(parse_cnf sst progress "") + rebuild=$(parse_cnf sst rebuild 0) + ttime=$(parse_cnf sst time 0) + cpat=$(parse_cnf sst cpat '.*galera\.cache$\|.*sst_in_progress$\|.*grastate\.dat$\|.*\.err$\|.*\.log$\|.*RPM_UPGRADE_MARKER$\|.*RPM_UPGRADE_HISTORY$') + incremental=$(parse_cnf sst incremental 0) + ealgo=$(parse_cnf xtrabackup encrypt "") + ekey=$(parse_cnf xtrabackup encrypt-key "") + ekeyfile=$(parse_cnf xtrabackup encrypt-key-file "") + scomp=$(parse_cnf sst compressor "") + sdecomp=$(parse_cnf sst decompressor "") + + + # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html + if [[ -z $ealgo ]];then + ealgo=$(parse_cnf sst encrypt-algo "") + ekey=$(parse_cnf sst encrypt-key "") + ekeyfile=$(parse_cnf sst encrypt-key-file "") + fi + rlimit=$(parse_cnf sst rlimit "") + uextra=$(parse_cnf sst use-extra 0) + speciald=$(parse_cnf sst sst-special-dirs 1) + iopts=$(parse_cnf sst inno-backup-opts "") + iapts=$(parse_cnf sst inno-apply-opts "") + impts=$(parse_cnf sst inno-move-opts "") + stimeout=$(parse_cnf sst sst-initial-timeout 100) +} + +get_stream() +{ + if [[ $sfmt == 'xbstream' ]];then + wsrep_log_info "Streaming with xbstream" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + strmcmd="xbstream -x" + else + strmcmd="xbstream -c \${INFO_FILE}" + fi + else + sfmt="tar" + wsrep_log_info "Streaming with tar" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + strmcmd="tar xfi - " + else + strmcmd="tar cf - \${INFO_FILE} " + fi + + fi +} + +get_proc() +{ + set +e + nproc=$(grep -c processor /proc/cpuinfo) + [[ -z $nproc || $nproc -eq 0 ]] && nproc=1 + set -e +} + +sig_joiner_cleanup() +{ + wsrep_log_error "Removing $MAGIC_FILE file due to signal" + rm -f "$MAGIC_FILE" +} + +cleanup_joiner() +{ + # Since this is invoked just after exit NNN + local estatus=$? + if [[ $estatus -ne 0 ]];then + wsrep_log_error "Cleanup after exit with status:$estatus" + fi + if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then + wsrep_log_info "Removing the sst_in_progress file" + wsrep_cleanup_progress_file + fi + if [[ -n $progress && -p $progress ]];then + wsrep_log_info "Cleaning up fifo file $progress" + rm $progress + fi + if [[ -n ${STATDIR:-} ]];then + [[ -d $STATDIR ]] && rm -rf $STATDIR + fi +} + +check_pid() +{ + local pid_file="$1" + [ -r "$pid_file" ] && ps -p $(cat "$pid_file") >/dev/null 2>&1 +} + +cleanup_donor() +{ + # Since this is invoked just after exit NNN + local estatus=$? + if [[ $estatus -ne 0 ]];then + wsrep_log_error "Cleanup after exit with status:$estatus" + fi + + if [[ -n ${XTRABACKUP_PID:-} ]];then + if check_pid $XTRABACKUP_PID + then + wsrep_log_error "xtrabackup process is still running. Killing... " + kill_xtrabackup + fi + + fi + rm -f ${DATA}/${IST_FILE} || true + + if [[ -n $progress && -p $progress ]];then + wsrep_log_info "Cleaning up fifo file $progress" + rm -f $progress || true + fi + + wsrep_log_info "Cleaning up temporary directories" + + if [[ -n $xtmpdir ]];then + [[ -d $xtmpdir ]] && rm -rf $xtmpdir || true + fi + + if [[ -n $itmpdir ]];then + [[ -d $itmpdir ]] && rm -rf $itmpdir || true + fi +} + +kill_xtrabackup() +{ + local PID=$(cat $XTRABACKUP_PID) + [ -n "$PID" -a "0" != "$PID" ] && kill $PID && (kill $PID && kill -9 $PID) || : + wsrep_log_info "Removing xtrabackup pid file $XTRABACKUP_PID" + rm -f "$XTRABACKUP_PID" || true +} + +setup_ports() +{ + if [[ "$WSREP_SST_OPT_ROLE" == "donor" ]];then + SST_PORT=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $2 }') + REMOTEIP=$(echo $WSREP_SST_OPT_ADDR | awk -F ':' '{ print $1 }') + lsn=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $4 }') + else + SST_PORT=$(echo ${WSREP_SST_OPT_ADDR} | awk -F ':' '{ print $2 }') + fi +} + +# waits ~10 seconds for nc to open the port and then reports ready +# (regardless of timeout) +wait_for_listen() +{ + local PORT=$1 + local ADDR=$2 + local MODULE=$3 + for i in {1..50} + do + ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break + sleep 0.2 + done + if [[ $incremental -eq 1 ]];then + echo "ready ${ADDR}/${MODULE}/$lsn" + else + echo "ready ${ADDR}/${MODULE}" + fi +} + +check_extra() +{ + local use_socket=1 + if [[ $uextra -eq 1 ]];then + if $my_print_defaults --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then + local eport=$($my_print_defaults --mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2) + if [[ -n $eport ]];then + # Xtrabackup works only locally. + # Hence, setting host to 127.0.0.1 unconditionally. + wsrep_log_info "SST through extra_port $eport" + INNOEXTRA+=" --host=127.0.0.1 --port=$eport " + use_socket=0 + else + wsrep_log_error "Extra port $eport null, failing" + exit 1 + fi + else + wsrep_log_info "Thread pool not set, ignore the option use_extra" + fi + fi + if [[ $use_socket -eq 1 ]] && [[ -n "${WSREP_SST_OPT_SOCKET}" ]];then + INNOEXTRA+=" --socket=${WSREP_SST_OPT_SOCKET}" + fi +} + +recv_joiner() +{ + local dir=$1 + local msg=$2 + local tmt=$3 + local ltcmd + + pushd ${dir} 1>/dev/null + set +e + + if [[ $tmt -gt 0 && -x `which timeout` ]];then + if timeout --help | grep -q -- '-k';then + ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd" + else + ltcmd="timeout $tmt $tcmd" + fi + timeit "$msg" "$ltcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" + else + timeit "$msg" "$tcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" + fi + + set -e + popd 1>/dev/null + + if [[ ${RC[0]} -eq 124 ]];then + wsrep_log_error "Possible timeout in receving first data from donor in gtid stage" + exit 32 + fi + + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then + wsrep_log_error "Error while getting data from donor node: " \ + "exit codes: ${RC[@]}" + exit 32 + fi + done + + if [ ! -r "${MAGIC_FILE}" ];then + # this message should cause joiner to abort + wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" + wsrep_log_info "Contents of datadir" + wsrep_log_info "$(ls -l ${dir}/*)" + exit 32 + fi +} + + +send_donor() +{ + local dir=$1 + local msg=$2 + + pushd ${dir} 1>/dev/null + set +e + timeit "$msg" "$strmcmd | $tcmd; RC=( "\${PIPESTATUS[@]}" )" + set -e + popd 1>/dev/null + + + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then + wsrep_log_error "Error while getting data from donor node: " \ + "exit codes: ${RC[@]}" + exit 32 + fi + done + +} + +if [[ ! -x `which $INNOBACKUPEX_BIN` ]];then + wsrep_log_error "innobackupex not in path: $PATH" + exit 2 +fi + +rm -f "${MAGIC_FILE}" + +if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then + wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" + exit 22 +fi + +read_cnf +setup_ports +get_stream +get_transfer + +if ${INNOBACKUPEX_BIN} /tmp --help | grep -q -- '--version-check'; then + disver="--no-version-check" +fi + + +INNOEXTRA="" +INNOAPPLY="${INNOBACKUPEX_BIN} $disver $iapts --apply-log \$rebuildcmd \${DATA} &>\${DATA}/innobackup.prepare.log" +INNOMOVE="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $impts --move-back --force-non-empty-directories \${DATA} &>\${DATA}/innobackup.move.log" +INNOBACKUP="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt \$itmpdir 2>\${DATA}/innobackup.backup.log" + +if [ "$WSREP_SST_OPT_ROLE" = "donor" ] +then + trap cleanup_donor EXIT + + if [ $WSREP_SST_OPT_BYPASS -eq 0 ] + then + + if [[ -z $(parse_cnf mysqld tmpdir "") && -z $(parse_cnf xtrabackup tmpdir "") ]];then + xtmpdir=$(mktemp -d) + tmpopts=" --tmpdir=$xtmpdir " + wsrep_log_info "Using $xtmpdir as xtrabackup temporary directory" + fi + + itmpdir=$(mktemp -d) + wsrep_log_info "Using $itmpdir as innobackupex temporary directory" + + if [ "${AUTH[0]}" != "(null)" ]; then + INNOEXTRA+=" --user=${AUTH[0]}" + fi + + if [ ${#AUTH[*]} -eq 2 ]; then + INNOEXTRA+=" --password=${AUTH[1]}" + elif [ "${AUTH[0]}" != "(null)" ]; then + # Empty password, used for testing, debugging etc. + INNOEXTRA+=" --password=" + fi + + get_keys + if [[ $encrypt -eq 1 ]];then + if [[ -n $ekey ]];then + INNOEXTRA+=" --encrypt=$ealgo --encrypt-key=$ekey " + else + INNOEXTRA+=" --encrypt=$ealgo --encrypt-key-file=$ekeyfile " + fi + fi + + if [[ -n $lsn ]];then + INNOEXTRA+=" --incremental --incremental-lsn=$lsn " + fi + + check_extra + + wsrep_log_info "Streaming GTID file before SST" + + # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id + # (separated by a space). + echo "${WSREP_SST_OPT_GTID} ${WSREP_SST_OPT_GTID_DOMAIN_ID}" > "${MAGIC_FILE}" + + ttcmd="$tcmd" + + if [[ $encrypt -eq 1 ]];then + if [[ -n $scomp ]];then + tcmd=" $ecmd | $scomp | $tcmd " + else + tcmd=" $ecmd | $tcmd " + fi + elif [[ -n $scomp ]];then + tcmd=" $scomp | $tcmd " + fi + + + send_donor $DATA "${stagemsg}-gtid" + + tcmd="$ttcmd" + if [[ -n $progress ]];then + get_footprint + tcmd="$pcmd | $tcmd" + elif [[ -n $rlimit ]];then + adjust_progress + tcmd="$pcmd | $tcmd" + fi + + wsrep_log_info "Sleeping before data transfer for SST" + sleep 10 + + wsrep_log_info "Streaming the backup to joiner at ${REMOTEIP} ${SST_PORT:-4444}" + + if [[ -n $scomp ]];then + tcmd="$scomp | $tcmd" + fi + + set +e + timeit "${stagemsg}-SST" "$INNOBACKUP | $tcmd; RC=( "\${PIPESTATUS[@]}" )" + set -e + + if [ ${RC[0]} -ne 0 ]; then + wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ + "Check ${DATA}/innobackup.backup.log" + exit 22 + elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + wsrep_log_error "$tcmd finished with error: ${RC[1]}" + exit 22 + fi + + # innobackupex implicitly writes PID to fixed location in $xtmpdir + XTRABACKUP_PID="$xtmpdir/xtrabackup_pid" + + + else # BYPASS FOR IST + + wsrep_log_info "Bypassing the SST for IST" + echo "continue" # now server can resume updating data + + # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id + # (separated by a space). + echo "${WSREP_SST_OPT_GTID} ${WSREP_SST_OPT_GTID_DOMAIN_ID}" > "${MAGIC_FILE}" + echo "1" > "${DATA}/${IST_FILE}" + get_keys + if [[ $encrypt -eq 1 ]];then + if [[ -n $scomp ]];then + tcmd=" $ecmd | $scomp | $tcmd " + else + tcmd=" $ecmd | $tcmd " + fi + elif [[ -n $scomp ]];then + tcmd=" $scomp | $tcmd " + fi + strmcmd+=" \${IST_FILE}" + + send_donor $DATA "${stagemsg}-IST" + + fi + + echo "done ${WSREP_SST_OPT_GTID}" + wsrep_log_info "Total time on donor: $totime seconds" + +elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ] +then + [[ -e $SST_PROGRESS_FILE ]] && wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" + [[ -n $SST_PROGRESS_FILE ]] && touch $SST_PROGRESS_FILE + + if [[ $speciald -eq 1 ]];then + ib_home_dir=$(parse_cnf mysqld innodb-data-home-dir "") + ib_log_dir=$(parse_cnf mysqld innodb-log-group-home-dir "") + if [[ -z $ib_home_dir && -z $ib_log_dir ]];then + speciald=0 + fi + fi + + stagemsg="Joiner-Recv" + + if [[ ! -e ${DATA}/ibdata1 ]];then + incremental=0 + fi + + if [[ $incremental -eq 1 ]];then + wsrep_log_info "Incremental SST enabled: NOT SUPPORTED yet" + lsn=$(grep to_lsn xtrabackup_checkpoints | cut -d= -f2 | tr -d ' ') + wsrep_log_info "Recovered LSN: $lsn" + fi + + sencrypted=1 + nthreads=1 + + MODULE="xtrabackup_sst" + + rm -f "${DATA}/${IST_FILE}" + + # May need xtrabackup_checkpoints later on + rm -f ${DATA}/xtrabackup_binary ${DATA}/xtrabackup_galera_info ${DATA}/xtrabackup_logfile + + ADDR=${WSREP_SST_OPT_ADDR} + if [ -z "${SST_PORT}" ] + then + SST_PORT=4444 + ADDR="$(echo ${WSREP_SST_OPT_ADDR} | awk -F ':' '{ print $1 }'):${SST_PORT}" + fi + + wait_for_listen ${SST_PORT} ${ADDR} ${MODULE} & + + trap sig_joiner_cleanup HUP PIPE INT TERM + trap cleanup_joiner EXIT + + if [[ -n $progress ]];then + adjust_progress + tcmd+=" | $pcmd" + fi + + if [[ $incremental -eq 1 ]];then + BDATA=$DATA + DATA=$(mktemp -d) + MAGIC_FILE="${DATA}/${INFO_FILE}" + fi + + get_keys + if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then + if [[ -n $sdecomp ]];then + strmcmd=" $sdecomp | $ecmd | $strmcmd" + else + strmcmd=" $ecmd | $strmcmd" + fi + elif [[ -n $sdecomp ]];then + strmcmd=" $sdecomp | $strmcmd" + fi + + STATDIR=$(mktemp -d) + MAGIC_FILE="${STATDIR}/${INFO_FILE}" + recv_joiner $STATDIR "${stagemsg}-gtid" $stimeout + + if ! ps -p ${WSREP_SST_OPT_PARENT} &>/dev/null + then + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + exit 32 + fi + + if [ ! -r "${STATDIR}/${IST_FILE}" ] + then + wsrep_log_info "Proceeding with SST" + + if [[ $speciald -eq 1 && -d ${DATA}/.sst ]];then + wsrep_log_info "WARNING: Stale temporary SST directory: ${DATA}/.sst from previous SST" + fi + + if [[ $incremental -ne 1 ]];then + if [[ $speciald -eq 1 ]];then + wsrep_log_info "Cleaning the existing datadir and innodb-data/log directories" + find $ib_home_dir $ib_log_dir $DATA -mindepth 1 -regex $cpat -prune -o -exec rm -rfv {} 1>&2 \+ + else + wsrep_log_info "Cleaning the existing datadir" + find $DATA -mindepth 1 -regex $cpat -prune -o -exec rm -rfv {} 1>&2 \+ + fi + tempdir=$(parse_cnf mysqld log-bin "") + if [[ -n ${tempdir:-} ]];then + binlog_dir=$(dirname $tempdir) + binlog_file=$(basename $tempdir) + if [[ -n ${binlog_dir:-} && $binlog_dir != '.' && $binlog_dir != $DATA ]];then + pattern="$binlog_dir/$binlog_file\.[0-9]+$" + wsrep_log_info "Cleaning the binlog directory $binlog_dir as well" + find $binlog_dir -maxdepth 1 -type f -regex $pattern -exec rm -fv {} 1>&2 \+ + rm $binlog_dir/*.index || true + fi + fi + + else + wsrep_log_info "Removing existing ib_logfile files" + rm -f ${BDATA}/ib_logfile* + fi + + + if [[ $speciald -eq 1 ]];then + mkdir -p ${DATA}/.sst + TDATA=${DATA} + DATA="${DATA}/.sst" + fi + + + MAGIC_FILE="${DATA}/${INFO_FILE}" + recv_joiner $DATA "${stagemsg}-SST" 0 + + get_proc + + # Rebuild indexes for compact backups + if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + wsrep_log_info "Index compaction detected" + rebuild=1 + fi + + if [[ $rebuild -eq 1 ]];then + nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) + wsrep_log_info "Rebuilding during prepare with $nthreads threads" + rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" + fi + + if test -n "$(find ${DATA} -maxdepth 1 -type f -name '*.qp' -print -quit)";then + + wsrep_log_info "Compressed qpress files found" + + if [[ ! -x `which qpress` ]];then + wsrep_log_error "qpress not found in path: $PATH" + exit 22 + fi + + if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then + count=$(find ${DATA} -type f -name '*.qp' | wc -l) + count=$(( count*2 )) + if pv --help | grep -q FORMAT;then + pvopts="-f -s $count -l -N Decompression -F '%N => Rate:%r Elapsed:%t %e Progress: [%b/$count]'" + else + pvopts="-f -s $count -l -N Decompression" + fi + pcmd="pv $pvopts" + adjust_progress + dcmd="$pcmd | xargs -n 2 qpress -T${nproc}d" + else + dcmd="xargs -n 2 qpress -T${nproc}d" + fi + + + # Decompress the qpress files + wsrep_log_info "Decompression with $nproc threads" + timeit "Joiner-Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" + extcode=$? + + if [[ $extcode -eq 0 ]];then + wsrep_log_info "Removing qpress files after decompression" + find ${DATA} -type f -name '*.qp' -delete + if [[ $? -ne 0 ]];then + wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" + fi + else + wsrep_log_error "Decompression failed. Exit code: $extcode" + exit 22 + fi + fi + + + if [[ ! -z $WSREP_SST_OPT_BINLOG ]];then + + BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG) + BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG) + + # To avoid comparing data directory and BINLOG_DIRNAME + mv $DATA/${BINLOG_FILENAME}.* $BINLOG_DIRNAME/ 2>/dev/null || true + + pushd $BINLOG_DIRNAME &>/dev/null + for bfiles in $(ls -1 ${BINLOG_FILENAME}.*);do + echo ${BINLOG_DIRNAME}/${bfiles} >> ${BINLOG_FILENAME}.index + done + popd &> /dev/null + + fi + + if [[ $incremental -eq 1 ]];then + # Added --ibbackup=xtrabackup_55 because it fails otherwise citing connection issues. + INNOAPPLY="${INNOBACKUPEX_BIN} $disver ${WSREP_SST_OPT_CONF} \ + --ibbackup=xtrabackup_56 --apply-log $rebuildcmd --redo-only $BDATA --incremental-dir=${DATA} &>>${BDATA}/innobackup.prepare.log" + fi + + wsrep_log_info "Preparing the backup at ${DATA}" + timeit "Xtrabackup prepare stage" "$INNOAPPLY" + + if [ $? -ne 0 ]; + then + wsrep_log_error "${INNOBACKUPEX_BIN} apply finished with errors. Check ${DATA}/innobackup.prepare.log" + exit 22 + fi + + if [[ $speciald -eq 1 ]];then + MAGIC_FILE="${TDATA}/${INFO_FILE}" + set +e + rm $TDATA/innobackup.prepare.log $TDATA/innobackup.move.log + set -e + wsrep_log_info "Moving the backup to ${TDATA}" + timeit "Xtrabackup move stage" "$INNOMOVE" + if [[ $? -eq 0 ]];then + wsrep_log_info "Move successful, removing ${DATA}" + rm -rf $DATA + DATA=${TDATA} + else + wsrep_log_error "Move failed, keeping ${DATA} for further diagnosis" + wsrep_log_error "Check ${DATA}/innobackup.move.log for details" + fi + fi + + if [[ $incremental -eq 1 ]];then + wsrep_log_info "Cleaning up ${DATA} after incremental SST" + [[ -d ${DATA} ]] && rm -rf ${DATA} + DATA=$BDATA + fi + + else + wsrep_log_info "${IST_FILE} received from donor: Running IST" + fi + + if [[ ! -r ${MAGIC_FILE} ]];then + wsrep_log_error "SST magic file ${MAGIC_FILE} not found/readable" + exit 2 + fi + cat "${MAGIC_FILE}" # Output : UUID:seqno wsrep_gtid_domain_id + wsrep_log_info "Total time on joiner: $totime seconds" +fi + +exit 0 diff --git a/scripts/wsrep_sst_xtrabackup.sh b/scripts/wsrep_sst_xtrabackup.sh new file mode 100644 index 00000000000..131eda765de --- /dev/null +++ b/scripts/wsrep_sst_xtrabackup.sh @@ -0,0 +1,716 @@ +#!/bin/bash -ue +# Copyright (C) 2013 Percona Inc +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston +# MA 02110-1301 USA. + +# Optional dependencies and options documented here: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html +# Make sure to read that before proceeding! + + + + +. $(dirname $0)/wsrep_sst_common + +ealgo="" +ekey="" +ekeyfile="" +encrypt=0 +nproc=1 +ecode=0 +XTRABACKUP_PID="" +SST_PORT="" +REMOTEIP="" +tcert="" +tpem="" +sockopt="" +progress="" +ttime=0 +totime=0 +lsn="" +incremental=0 +ecmd="" +rlimit="" + +sfmt="tar" +strmcmd="" +tfmt="" +tcmd="" +rebuild=0 +rebuildcmd="" +payload=0 +pvformat="-F '%N => Rate:%r Avg:%a Elapsed:%t %e Bytes: %b %p' " +pvopts="-f -i 10 -N $WSREP_SST_OPT_ROLE " +uextra=0 + +if which pv &>/dev/null && pv --help | grep -q FORMAT;then + pvopts+=$pvformat +fi +pcmd="pv $pvopts" +declare -a RC + +INNOBACKUPEX_BIN=innobackupex +readonly AUTH=(${WSREP_SST_OPT_AUTH//:/ }) +DATA="${WSREP_SST_OPT_DATA}" +INFO_FILE="xtrabackup_galera_info" +IST_FILE="xtrabackup_ist" +MAGIC_FILE="${DATA}/${INFO_FILE}" + +# Setting the path for ss and ip +export PATH="/usr/sbin:/sbin:$PATH" + +timeit(){ + local stage=$1 + shift + local cmd="$@" + local x1 x2 took extcode + + if [[ $ttime -eq 1 ]];then + x1=$(date +%s) + wsrep_log_info "Evaluating $cmd" + eval "$cmd" + extcode=$? + x2=$(date +%s) + took=$(( x2-x1 )) + wsrep_log_info "NOTE: $stage took $took seconds" + totime=$(( totime+took )) + else + wsrep_log_info "Evaluating $cmd" + eval "$cmd" + extcode=$? + fi + return $extcode +} + +get_keys() +{ + if [[ $encrypt -eq 2 ]];then + return + fi + + if [[ $encrypt -eq 0 ]];then + if $my_print_defaults xtrabackup | grep -q encrypt;then + wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html " + fi + return + fi + + if [[ $sfmt == 'tar' ]];then + wsrep_log_info "NOTE: Xtrabackup-based encryption - encrypt=1 - cannot be enabled with tar format" + encrypt=0 + return + fi + + wsrep_log_info "Xtrabackup based encryption enabled in my.cnf - Supported only from Xtrabackup 2.1.4" + + if [[ -z $ealgo ]];then + wsrep_log_error "FATAL: Encryption algorithm empty from my.cnf, bailing out" + exit 3 + fi + + if [[ -z $ekey && ! -r $ekeyfile ]];then + wsrep_log_error "FATAL: Either key or keyfile must be readable" + exit 3 + fi + + if [[ -z $ekey ]];then + ecmd="xbcrypt --encrypt-algo=$ealgo --encrypt-key-file=$ekeyfile" + else + ecmd="xbcrypt --encrypt-algo=$ealgo --encrypt-key=$ekey" + fi + + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + ecmd+=" -d" + fi +} + +get_transfer() +{ + if [[ -z $SST_PORT ]];then + TSST_PORT=4444 + else + TSST_PORT=$SST_PORT + fi + + if [[ $tfmt == 'nc' ]];then + if [[ ! -x `which nc` ]];then + wsrep_log_error "nc(netcat) not found in path: $PATH" + exit 2 + fi + wsrep_log_info "Using netcat as streamer" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + tcmd="nc -dl ${TSST_PORT}" + else + tcmd="nc ${REMOTEIP} ${TSST_PORT}" + fi + else + tfmt='socat' + wsrep_log_info "Using socat as streamer" + if [[ ! -x `which socat` ]];then + wsrep_log_error "socat not found in path: $PATH" + exit 2 + fi + + if [[ $encrypt -eq 2 ]] && ! socat -V | grep -q OPENSSL;then + wsrep_log_info "NOTE: socat is not openssl enabled, falling back to plain transfer" + encrypt=0 + fi + + if [[ $encrypt -eq 2 ]];then + wsrep_log_info "Using openssl based encryption with socat" + if [[ -z $tpem || -z $tcert ]];then + wsrep_log_error "Both PEM and CRT files required" + exit 22 + fi + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + wsrep_log_info "Decrypting with PEM $tpem, CA: $tcert" + tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=$tpem,cafile=${tcert}${sockopt} stdio" + else + wsrep_log_info "Encrypting with PEM $tpem, CA: $tcert" + tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=$tpem,cafile=${tcert}${sockopt}" + fi + else + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio" + else + tcmd="socat -u stdio TCP:${REMOTEIP}:${TSST_PORT}${sockopt}" + fi + fi + fi + +} + +parse_cnf() +{ + local group=$1 + local var=$2 + reval=$($my_print_defaults $group | awk -F= '{if ($1 ~ /_/) { gsub(/_/,"-",$1); print $1"="$2 } else { print $0 }}' | grep -- "--$var=" | cut -d= -f2-) + if [[ -z $reval ]];then + [[ -n $3 ]] && reval=$3 + fi + echo $reval +} + +get_footprint() +{ + pushd $WSREP_SST_OPT_DATA 1>/dev/null + payload=$(find . -regex '.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' -type f -print0 | du --files0-from=- --block-size=1 -c | awk 'END { print $1 }') + if $my_print_defaults xtrabackup | grep -q -- "--compress";then + # QuickLZ has around 50% compression ratio + # When compression/compaction used, the progress is only an approximate. + payload=$(( payload*1/2 )) + fi + popd 1>/dev/null + pcmd+=" -s $payload" + adjust_progress +} + +adjust_progress() +{ + if [[ -n $progress && $progress != '1' ]];then + if [[ -e $progress ]];then + pcmd+=" 2>>$progress" + else + pcmd+=" 2>$progress" + fi + elif [[ -z $progress && -n $rlimit ]];then + # When rlimit is non-zero + pcmd="pv -q" + fi + + if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then + wsrep_log_info "Rate-limiting SST to $rlimit" + pcmd+=" -L \$rlimit" + fi +} + +read_cnf() +{ + sfmt=$(parse_cnf sst streamfmt "tar") + tfmt=$(parse_cnf sst transferfmt "socat") + tcert=$(parse_cnf sst tca "") + tpem=$(parse_cnf sst tcert "") + encrypt=$(parse_cnf sst encrypt 0) + sockopt=$(parse_cnf sst sockopt "") + progress=$(parse_cnf sst progress "") + rebuild=$(parse_cnf sst rebuild 0) + ttime=$(parse_cnf sst time 0) + incremental=$(parse_cnf sst incremental 0) + ealgo=$(parse_cnf xtrabackup encrypt "") + ekey=$(parse_cnf xtrabackup encrypt-key "") + ekeyfile=$(parse_cnf xtrabackup encrypt-key-file "") + + # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html + if [[ -z $ealgo ]];then + ealgo=$(parse_cnf sst encrypt-algo "") + ekey=$(parse_cnf sst encrypt-key "") + ekeyfile=$(parse_cnf sst encrypt-key-file "") + fi + rlimit=$(parse_cnf sst rlimit "") + uextra=$(parse_cnf sst use_extra 0) +} + +get_stream() +{ + if [[ $sfmt == 'xbstream' ]];then + wsrep_log_info "Streaming with xbstream" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + strmcmd="xbstream -x" + else + strmcmd="xbstream -c \${INFO_FILE} \${IST_FILE}" + fi + else + sfmt="tar" + wsrep_log_info "Streaming with tar" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + strmcmd="tar xfi - --recursive-unlink -h" + else + strmcmd="tar cf - \${INFO_FILE} \${IST_FILE}" + fi + + fi +} + +get_proc() +{ + set +e + nproc=$(grep -c processor /proc/cpuinfo) + [[ -z $nproc || $nproc -eq 0 ]] && nproc=1 + set -e +} + +sig_joiner_cleanup() +{ + wsrep_log_error "Removing $MAGIC_FILE file due to signal" + rm -f "$MAGIC_FILE" +} + +cleanup_joiner() +{ + # Since this is invoked just after exit NNN + local estatus=$? + if [[ $estatus -ne 0 ]];then + wsrep_log_error "Cleanup after exit with status:$estatus" + fi + if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then + wsrep_log_info "Removing the sst_in_progress file" + wsrep_cleanup_progress_file + fi + if [[ -n $progress && -p $progress ]];then + wsrep_log_info "Cleaning up fifo file $progress" + rm $progress + fi +} + +check_pid() +{ + local pid_file="$1" + [ -r "$pid_file" ] && ps -p $(cat "$pid_file") >/dev/null 2>&1 +} + +cleanup_donor() +{ + # Since this is invoked just after exit NNN + local estatus=$? + if [[ $estatus -ne 0 ]];then + wsrep_log_error "Cleanup after exit with status:$estatus" + fi + + if [[ -n $XTRABACKUP_PID ]];then + if check_pid $XTRABACKUP_PID + then + wsrep_log_error "xtrabackup process is still running. Killing... " + kill_xtrabackup + fi + + rm -f $XTRABACKUP_PID + fi + rm -f ${DATA}/${IST_FILE} + + if [[ -n $progress && -p $progress ]];then + wsrep_log_info "Cleaning up fifo file $progress" + rm $progress + fi +} + +kill_xtrabackup() +{ + local PID=$(cat $XTRABACKUP_PID) + [ -n "$PID" -a "0" != "$PID" ] && kill $PID && (kill $PID && kill -9 $PID) || : + rm -f "$XTRABACKUP_PID" +} + +setup_ports() +{ + if [[ "$WSREP_SST_OPT_ROLE" == "donor" ]];then + SST_PORT=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $2 }') + REMOTEIP=$(echo $WSREP_SST_OPT_ADDR | awk -F ':' '{ print $1 }') + lsn=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $4 }') + else + SST_PORT=$(echo ${WSREP_SST_OPT_ADDR} | awk -F ':' '{ print $2 }') + fi +} + +# waits ~10 seconds for nc to open the port and then reports ready +# (regardless of timeout) +wait_for_listen() +{ + local PORT=$1 + local ADDR=$2 + local MODULE=$3 + for i in {1..50} + do + ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break + sleep 0.2 + done + if [[ $incremental -eq 1 ]];then + echo "ready ${ADDR}/${MODULE}/$lsn" + else + echo "ready ${ADDR}/${MODULE}" + fi +} + +check_extra() +{ + local use_socket=1 + if [[ $uextra -eq 1 ]];then + if $my_print_defaults --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then + local eport=$($my_print_defaults --mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2) + if [[ -n $eport ]];then + # Xtrabackup works only locally. + # Hence, setting host to 127.0.0.1 unconditionally. + wsrep_log_info "SST through extra_port $eport" + INNOEXTRA+=" --host=127.0.0.1 --port=$eport " + use_socket=0 + else + wsrep_log_error "Extra port $eport null, failing" + exit 1 + fi + else + wsrep_log_info "Thread pool not set, ignore the option use_extra" + fi + fi + if [[ $use_socket -eq 1 ]] && [[ -n "${WSREP_SST_OPT_SOCKET}" ]];then + INNOEXTRA+=" --socket=${WSREP_SST_OPT_SOCKET}" + fi +} + +if [[ ! -x `which innobackupex` ]];then + wsrep_log_error "innobackupex not in path: $PATH" + exit 2 +fi + +rm -f "${MAGIC_FILE}" + +if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then + wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" + exit 22 +fi + +read_cnf +setup_ports +get_stream +get_transfer + +INNOEXTRA="" +INNOAPPLY="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} --apply-log \$rebuildcmd \${DATA} &>\${DATA}/innobackup.prepare.log" +INNOBACKUP="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} \$INNOEXTRA --galera-info --stream=\$sfmt \${TMPDIR} 2>\${DATA}/innobackup.backup.log" + +if [ "$WSREP_SST_OPT_ROLE" = "donor" ] +then + trap cleanup_donor EXIT + + if [ $WSREP_SST_OPT_BYPASS -eq 0 ] + then + TMPDIR="${TMPDIR:-/tmp}" + + if [ "${AUTH[0]}" != "(null)" ]; then + INNOEXTRA+=" --user=${AUTH[0]}" + fi + + if [ ${#AUTH[*]} -eq 2 ]; then + INNOEXTRA+=" --password=${AUTH[1]}" + elif [ "${AUTH[0]}" != "(null)" ]; then + # Empty password, used for testing, debugging etc. + INNOEXTRA+=" --password=" + fi + + get_keys + if [[ $encrypt -eq 1 ]];then + if [[ -n $ekey ]];then + INNOEXTRA+=" --encrypt=$ealgo --encrypt-key=$ekey " + else + INNOEXTRA+=" --encrypt=$ealgo --encrypt-key-file=$ekeyfile " + fi + fi + + if [[ -n $lsn ]];then + INNOEXTRA+=" --incremental --incremental-lsn=$lsn " + fi + + check_extra + + wsrep_log_info "Streaming the backup to joiner at ${REMOTEIP} ${SST_PORT}" + + if [[ -n $progress ]];then + get_footprint + tcmd="$pcmd | $tcmd" + elif [[ -n $rlimit ]];then + adjust_progress + tcmd="$pcmd | $tcmd" + fi + + set +e + timeit "Donor-Transfer" "$INNOBACKUP | $tcmd; RC=( "\${PIPESTATUS[@]}" )" + set -e + + if [ ${RC[0]} -ne 0 ]; then + wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ + "Check ${DATA}/innobackup.backup.log" + exit 22 + elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + wsrep_log_error "$tcmd finished with error: ${RC[1]}" + exit 22 + fi + + # innobackupex implicitly writes PID to fixed location in ${TMPDIR} + XTRABACKUP_PID="${TMPDIR}/xtrabackup_pid" + + else # BYPASS FOR IST + + wsrep_log_info "Bypassing the SST for IST" + echo "continue" # now server can resume updating data + + # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id + # (separated by a space) + echo "${WSREP_SST_OPT_GTID} ${WSREP_SST_OPT_GTID_DOMAIN_ID}" > "${MAGIC_FILE}" + echo "1" > "${DATA}/${IST_FILE}" + get_keys + pushd ${DATA} 1>/dev/null + set +e + if [[ $encrypt -eq 1 ]];then + tcmd=" $ecmd | $tcmd" + fi + timeit "Donor-IST-Unencrypted-transfer" "$strmcmd | $tcmd; RC=( "\${PIPESTATUS[@]}" )" + set -e + popd 1>/dev/null + + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then + wsrep_log_error "Error while streaming data to joiner node: " \ + "exit codes: ${RC[@]}" + exit 1 + fi + done + fi + + echo "done ${WSREP_SST_OPT_GTID}" + wsrep_log_info "Total time on donor: $totime seconds" + +elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ] +then + [[ -e $SST_PROGRESS_FILE ]] && wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" + touch $SST_PROGRESS_FILE + + if [[ ! -e ${DATA}/ibdata1 ]];then + incremental=0 + fi + + if [[ $incremental -eq 1 ]];then + wsrep_log_info "Incremental SST enabled" + #lsn=$(/pxc/bin/mysqld $WSREP_SST_OPT_CONF --basedir=/pxc --wsrep-recover 2>&1 | grep -o 'log sequence number .*' | cut -d " " -f 4 | head -1) + lsn=$(grep to_lsn xtrabackup_checkpoints | cut -d= -f2 | tr -d ' ') + wsrep_log_info "Recovered LSN: $lsn" + fi + + sencrypted=1 + nthreads=1 + + MODULE="xtrabackup_sst" + + # May need xtrabackup_checkpoints later on + rm -f ${DATA}/xtrabackup_binary ${DATA}/xtrabackup_galera_info ${DATA}/xtrabackup_logfile + + ADDR=${WSREP_SST_OPT_ADDR} + if [ -z "${SST_PORT}" ] + then + SST_PORT=4444 + ADDR="$(echo ${WSREP_SST_OPT_ADDR} | awk -F ':' '{ print $1 }'):${SST_PORT}" + fi + + wait_for_listen ${SST_PORT} ${ADDR} ${MODULE} & + + trap sig_joiner_cleanup HUP PIPE INT TERM + trap cleanup_joiner EXIT + + if [[ -n $progress ]];then + adjust_progress + tcmd+=" | $pcmd" + fi + + if [[ $incremental -eq 1 ]];then + BDATA=$DATA + DATA=$(mktemp -d) + MAGIC_FILE="${DATA}/${INFO_FILE}" + fi + + get_keys + set +e + if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then + strmcmd=" $ecmd | $strmcmd" + fi + + pushd ${DATA} 1>/dev/null + timeit "Joiner-Recv-Unencrypted" "$tcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" + popd 1>/dev/null + + set -e + + if [[ $sfmt == 'xbstream' ]];then + # Special handling till lp:1193240 is fixed" + if [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + wsrep_log_error "Xbstream failed" + wsrep_log_error "Data directory ${DATA} may not be empty: lp:1193240" \ + "Manual intervention required in that case" + exit 32 + fi + fi + + wait %% # join for wait_for_listen thread + + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then + wsrep_log_error "Error while getting data from donor node: " \ + "exit codes: ${RC[@]}" + exit 32 + fi + done + + if [ ! -r "${MAGIC_FILE}" ] + then + # this message should cause joiner to abort + wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" + wsrep_log_info "Contents of datadir" + wsrep_log_info "$(ls -l ${DATA}/**/*)" + exit 32 + fi + + if ! ps -p ${WSREP_SST_OPT_PARENT} &>/dev/null + then + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + exit 32 + fi + + if [ ! -r "${DATA}/${IST_FILE}" ] + then + wsrep_log_info "Proceeding with SST" + wsrep_log_info "Removing existing ib_logfile files" + if [[ $incremental -ne 1 ]];then + rm -f ${DATA}/ib_logfile* + else + rm -f ${BDATA}/ib_logfile* + fi + + get_proc + + # Rebuild indexes for compact backups + if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + wsrep_log_info "Index compaction detected" + rebuild=1 + fi + + if [[ $rebuild -eq 1 ]];then + nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) + wsrep_log_info "Rebuilding during prepare with $nthreads threads" + rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" + fi + + if test -n "$(find ${DATA} -maxdepth 1 -type f -name '*.qp' -print -quit)";then + + wsrep_log_info "Compressed qpress files found" + + if [[ ! -x `which qpress` ]];then + wsrep_log_error "qpress not found in path: $PATH" + exit 22 + fi + + if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then + count=$(find ${DATA} -type f -name '*.qp' | wc -l) + count=$(( count*2 )) + if pv --help | grep -q FORMAT;then + pvopts="-f -s $count -l -N Decompression -F '%N => Rate:%r Elapsed:%t %e Progress: [%b/$count]'" + else + pvopts="-f -s $count -l -N Decompression" + fi + pcmd="pv $pvopts" + adjust_progress + dcmd="$pcmd | xargs -n 2 qpress -T${nproc}d" + else + dcmd="xargs -n 2 qpress -T${nproc}d" + fi + + wsrep_log_info "Removing existing ibdata1 file" + rm -f ${DATA}/ibdata1 + + # Decompress the qpress files + wsrep_log_info "Decompression with $nproc threads" + timeit "Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" + extcode=$? + + if [[ $extcode -eq 0 ]];then + wsrep_log_info "Removing qpress files after decompression" + find ${DATA} -type f -name '*.qp' -delete + if [[ $? -ne 0 ]];then + wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" + fi + else + wsrep_log_error "Decompression failed. Exit code: $extcode" + exit 22 + fi + fi + + if [[ $incremental -eq 1 ]];then + # Added --ibbackup=xtrabackup_55 because it fails otherwise citing connection issues. + INNOAPPLY="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} \ + --ibbackup=xtrabackup_55 --apply-log $rebuildcmd --redo-only $BDATA --incremental-dir=${DATA} &>>${BDATA}/innobackup.prepare.log" + fi + + wsrep_log_info "Preparing the backup at ${DATA}" + timeit "Xtrabackup prepare stage" "$INNOAPPLY" + + if [[ $incremental -eq 1 ]];then + wsrep_log_info "Cleaning up ${DATA} after incremental SST" + [[ -d ${DATA} ]] && rm -rf ${DATA} + DATA=$BDATA + fi + + if [ $? -ne 0 ]; + then + wsrep_log_error "${INNOBACKUPEX_BIN} finished with errors. Check ${DATA}/innobackup.prepare.log" + exit 22 + fi + else + wsrep_log_info "${IST_FILE} received from donor: Running IST" + fi + + if [[ ! -r ${MAGIC_FILE} ]];then + wsrep_log_error "SST magic file ${MAGIC_FILE} not found/readable" + exit 2 + fi + + cat "${MAGIC_FILE}" # Output : UUID:seqno wsrep_gtid_domain_id + wsrep_log_info "Total time on joiner: $totime seconds" +fi + +exit 0 |