MySQL版本选择:
5.6 版本: GA 6-12个月 小版本是偶数版本
5.7 版本: GA 6-12个月 小版本是偶数版本 5.7.17以上版本 (MGR:高可用)
General Availability (GA) Releases
MySQL历史版本下载地址 https://downloads.mysql.com/archives/community/
GA版是软件产品正式发布的版本,也称生产版本的产品。
安装MySQL需要考虑的步骤
1 Determine whether MySQL runs and is supported on your platform.
https://www.mysql.com/support/supportedplatforms/database.html
2 Choose which distribution to install.
3 Download the distribution that you want to install.
4 Install the distribution.
a binary distribution or a source distribution
5 Perform any necessary postinstallation setup.
How to Get MySQL
https://dev.mysql.com/downloads/
https://dev.mysql.com/downloads/mirrors.html
https://dev.mysql.com/downloads/repo/yum/
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
########################## 需要安装的依赖 ##################################################
yum search libaio
yum search libnuma
yum install libaio numactl-libs
########################## 创建用户 ##########################################################
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
后面启动MySQL服务的时候指定这个用户,MySQL数据目录的权限需要授权为mysql用户
########################## 解压文件 ##########################################################
mkdir -p /xdata && cd /xdata
wget http://192.168.1.8/chfs/shared/mysql/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
官方文件下载地址 https://downloads.mysql.com/archives/community/
########################## 创建和授权数据目录 #############################################
cd /xdata/mysql-5.7.28-linux-glibc2.12-x86_64
mkdir -p /xdata/mysql-5.7.28-linux-glibc2.12-x86_64/data-mysql
chown -R mysql:mysql /xdata/mysql-5.7.28-linux-glibc2.12-x86_64/data-mysql
########################## 初始化数据目录 ##################################################
初始化的数据目录要保持为空,否则会报错
bin/mysqld --help --verbose &> /tmp/tmp.txt #这条命令可以查看到MySQL配置文件的生效顺序
bin/mysqld --initialize-insecure --user=mysql --basedir=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64 --datadir=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64/data-mysql
bin/mysql_ssl_rsa_setup --help
bin/mysql_ssl_rsa_setup --datadir=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64/data-mysql
########################## 增加配置文件 ##########################################################
cat << 'EOF' > /etc/my.cnf
[mysqld]
basedir=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64
datadir=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64/data-mysql
EOF
########################## 启动MySQL服务 ##############################################################
bin/mysqld_safe --user=mysql &
此时已经成功监听3306端口
ps aux | grep mysql
If the command fails immediately and prints mysqld ended, look for information in the error log (which by default is the host_name.err file in the data directory).
如果需要替换配置文件,可以使用
mysqld_safe --user=mysql --defaults-file=/data/3307/my.cnf &
########################## 修改root用户的密码 #####################################################
./bin/mysql -u root --skip-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password'"
./bin/mysql -u root -p'root-password' -e "select user,host from mysql.user"
########################## 检查MySQL运行状态 ######################################################
bin/mysqladmin -u root -p'root-password' version
bin/mysqladmin -u root -p'root-password' ping
bin/mysqladmin -u root -p'root-password' variables
bin/mysqladmin -u root -p'root-password' --help
########################## 启动和停止MySQL ########################################################
bin/mysqladmin -uroot -p'root-password' shutdown
bin/mysqld_safe --user=mysql &
########################## 配置systemd管理MySQL ###########################################################
cat << 'EOF' > /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
User=mysql
Group=mysql
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Start main service
ExecStart=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64/bin/mysqld_safe
# Give up if ping don't get an answer
TimeoutSec=600
Restart=always
PrivateTmp=false
EOF
systemctl daemon-reload
systemctl restart mysqld
systemctl status mysqld
systemctl enable mysqld
########################## 添加MySQL环境变量 ###########################################################
echo 'export PATH=/xdata/mysql-5.7.28-linux-glibc2.12-x86_64/bin:$PATH' >> /etc/profile
重新连接终端
echo $PATH
mysql -u root -p'root-password' -e "select user,host from mysql.user"
########################## 创建最高权限root用户 ###########################################################
默认安装的root用户只能在本地连接(localhost),如果我们希望其它机器也能连接这个MySQL,需要重新创建个账号
mysql -uroot -p'root-password' -e "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'root-password' WITH GRANT OPTION"
mysql -h$(hostname -I | awk '{print $1}') -uroot -p'root-password' -e "DROP USER 'root'@'localhost'"
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
http://192.168.31.50/chfs/shared/mysql/mysql80-community-release-el7-3.noarch.rpm
[root@node2 ~]# #yum install ./mysql80-community-release-el7-3.noarch.rpm
[root@node2 ~]# rpm -ql mysql80-community-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
/etc/yum.repos.d/mysql-community-source.repo
/etc/yum.repos.d/mysql-community.repo
yum install yum-utils
yum repolist all | grep mysql | grep enabled
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
[root@node2 ~]# yum repolist all | grep mysql | grep enabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 153
mysql-tools-community/x86_64 MySQL Tools Community enabled: 110
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 424
yum install mysql-community-server
systemctl start mysqld
shell> sudo grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
https://downloads.mysql.com/archives/community/
####################################### 解压 rpm tar 包 ##########################################################
mkdir -p /as4k/mysql && cd /as4k/mysql
wget http://192.168.1.8/chfs/shared/mysql/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
OR http://as4k.top:7000/chfs/shared/mysql/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
tar xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
####################################### 安装 #####################################################################
这一步的写法非常重要,我是直接把官方文档照搬下来的,不这样通配符形式的写,很可能会报一些依赖错误之类
yum install mysql-community-{server,client,common,libs}-* -y
有可能需要依赖 yum install libaio
####################################### 启动 #####################################################################
systemctl start mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service
####################################### 创建新的root账号 #####################################################################
MySQL5.7 YUM安装,启动的时候会指定初始化数据目录,并且生成一个随机密码,生成的root用户是面向localhost登录的,下面做的工作是,创建高权限跨机器可登录的root用户,删除旧的root用户,主要默认是开启了密码强度策略的,密码简单则无法创建
grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}'
XPWD=`grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}'`; echo $XPWD
mysql --connect-expired-password -uroot -p"$XPWD" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'As4k.top'"
mysql -uroot -p'As4k.top' -e "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'As4k.top' WITH GRANT OPTION"
mysql -h$(hostname -I | awk '{print $1}') -uroot -p'As4k.top' -e "DROP USER 'root'@'localhost'"
mysql -uroot -p'As4k.top' -e "select user,host from mysql.user"
windows
validate_password 为例
https://blog.csdn.net/kk185800961/article/details/79447754
################################## 未分类 ##################################################################
select * from error_queue_meta limit 10\G;
################################## 查看当前正在运行的SQL ##############################################################
show processlist;
################################## 连接和退出 ########################################################################
mysql --help
shell> mysql -h host -u user -p
shell> mysql -u root -p'As4k.top'
mysql> exit OR quit OR \q
mysql> \s
################################## 未分类 ########################################################################
如果输入的查询命令包含密码等敏感信息,比如下面的命令
mysql> select user,host,password from mysql.user;
使用上下按键翻的时候,是翻不出来,相当于没有记录。但是可以在日志记录里完全可以找到。
因此这个参数不太安全,生产中一般不太常用。该参数是基于session的,只在当前会话中生效,除非
配置在配置文件中。
在mysql命令行中,可以用\G,格式化查询,看起来的效果,就是横转竖向
命令敲错,在MySQL5.6中可以敲\c退出,而在5.7中可以使用CTRL+C直接取消当前命令。
在5.6中CTRL+C直接退出数据库。
################################## 不区分大小写 ########################################################################
MySQL的查询语句,不区分大小写,下面的写法效果一样
mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
################################## 多行输入 ########################################################################
Here is a simple multiple-line statement:
mysql> SELECT
USER(),
CURRENT_DATE;
################################## 取消输入 ########################################################################
取消当前输入 \c
Prompt Meaning
mysql> Ready for new query
-> Waiting for next line of multiple-line query
'> Waiting for next line, waiting for completion of a string that began with a single quote (')
"> Waiting for next line, waiting for completion of a string that began with a double quote (")
`> Waiting for next line, waiting for completion of an identifier that began with a backtick (`)
/*> Waiting for next line, waiting for completion of a comment that began with /*
################################## Creating and Using a Database ###################################################
SHOW DATABASES;
CREATE DATABASE xtest;
USE xtest
SHOW TABLES;
CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
DESCRIBE pet;
INSERT INTO pet
VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
################################## Retrieving Information from a Table ###############################################
SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy;
SELECT * FROM pet;
UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
Selecting Particular Rows
SELECT * FROM pet WHERE name = 'Bowser';
SELECT * FROM pet WHERE birth >= '1998-1-1';
SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
OR (species = 'dog' AND sex = 'f');
Selecting Particular Columns
SELECT name, birth FROM pet;
SELECT owner FROM pet;
SELECT DISTINCT owner FROM pet;
SELECT name, species, birth FROM pet
WHERE species = 'dog' OR species = 'cat';
Sorting Rows
SELECT name, birth FROM pet ORDER BY birth;
SELECT name, birth FROM pet ORDER BY birth DESC;
SELECT name, species, birth FROM pet
ORDER BY species, birth DESC;
Date Calculations
SELECT name, birth, CURDATE(),
TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age
FROM pet;
SELECT name, birth, CURDATE(),
TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age
FROM pet ORDER BY name;
SELECT name, birth, CURDATE(),
TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age
FROM pet ORDER BY age;
SELECT name, birth, death,
TIMESTAMPDIFF(YEAR,birth,death) AS age
FROM pet WHERE death IS NOT NULL ORDER BY age;
SELECT name, birth, MONTH(birth) FROM pet;
SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
Working with NULL Values
SELECT 1 IS NULL, 1 IS NOT NULL;
SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
SELECT 0 IS NULL, 0 IS NOT NULL, '' IS NULL, '' IS NOT NULL;
Pattern Matching
SELECT * FROM pet WHERE name LIKE 'b%';
SELECT * FROM pet WHERE name LIKE '%fy';
To find names containing a w
SELECT * FROM pet WHERE name LIKE '%w%';
To find names containing exactly five characters, use five instances of the _ pattern character:
SELECT * FROM pet WHERE name LIKE '_____';
SELECT * FROM pet WHERE name REGEXP '^b';
SELECT * FROM pet WHERE name REGEXP BINARY '^b';
SELECT * FROM pet WHERE name REGEXP 'w';
Counting Rows
SELECT COUNT(*) FROM pet;
SELECT owner, COUNT(*) FROM pet GROUP BY owner;
SELECT species, COUNT(*) FROM pet GROUP BY species;
Using More Than one Table
mysql> SELECT pet.name,
TIMESTAMPDIFF(YEAR,birth,date) AS age,
remark
FROM pet INNER JOIN event
ON pet.name = event.name
WHERE event.type = 'litter';
mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
FROM pet AS p1 INNER JOIN pet AS p2
ON p1.species = p2.species
AND p1.sex = 'f' AND p1.death IS NULL
AND p2.sex = 'm' AND p2.death IS NULL;
################################## Getting Information About Databases and Tables ##############################
SELECT DATABASE();
SHOW TABLES;
DESCRIBE pet;
################################## 排序 ########################################################################
mysql> select * from pipeline_info where data_as4k=467 ORDER BY pipeline_info_id DESC limit 5;
+------------------+------------------+---------+----------------+-------------------+-------------------------+---------------+-----------------------+---------------------+-------------------+-----------------+---------------+-------------------------+------------+-------------------------+------------+
| pipeline_info_id | data_as4k | dest_id | dest_schema_id | processed_records | total_processed_records | total_records | last_record_timestamp | last_sync_time | lastday_max_delay | today_max_delay | active_status | created_at | created_by | updated_at | updated_by |
+------------------+------------------+---------+----------------+-------------------+-------------------------+---------------+-----------------------+---------------------+-------------------+-----------------+---------------+-------------------------+------------+-------------------------+------------+
| 621919866 | 467 | 54 | 12908 | 1 | 28546996 | 28546996 | 2020-05-08 02:25:03 | 2020-05-08 02:26:25 | 234198 | 140345 | 1 | 2020-05-08 02:48:00.000 | 2 | 2020-05-08 02:48:00.000 | 2 |
| 621919865 | 467 | 54 | 15726 | 1 | 228 | 228 | 2020-04-03 06:36:59 | 2020-04-03 06:37:37 | NULL | NULL | 1 | 2020-05-08 02:48:00.000 | 2 | 2020-05-08 02:48:00.000 | 2 |
| 621919864 | 467 | 54 | 12910 | 44 | 6175 | 6175 | 2020-03-30 06:11:52 | 2020-03-30 06:12:42 | NULL | NULL | 1 | 2020-05-08 02:48:00.000 | 2 | 2020-05-08 02:48:00.000 | 2 |
| 621919863 | 467 | 54 | 16958 | 60 | 25360312 | 25360312 | 2020-05-08 02:45:18 | 2020-05-08 02:45:55 | 146173 | 712994 | 1 | 2020-05-08 02:48:00.000 | 2 | 2020-05-08 02:48:00.000 | 2 |
| 621919862 | 467 | 54 | 12911 | 1 | 25200 | 25200 | 2020-05-08 02:31:52 | 2020-05-08 02:32:25 | 31238 | 31489 | 1 | 2020-05-08 02:48:00.000 | 2 | 2020-05-08 02:48:00.000 | 2 |
+------------------+------------------+---------+----------------+-------------------+-------------------------+---------------+-----------------------+---------------------+-------------------+-----------------+---------------+-------------------------+------------+-------------------------+------------+
5 rows in set (0.01 sec)
################################## 删除 ########################################################################
MySQL DELETE 语句
DELETE FROM table_name [WHERE Clause]
DELETE FROM runoob_tbl WHERE runoob_id=3;
delete,drop,truncate 都有删除表的作用,区别在于:
1、delete 和 truncate 仅仅删除表数据,drop 连表数据和表结构一起删除,打个比方,delete 是单杀,truncate 是团灭,drop 是把电脑摔了。
2、delete 是 DML 语句,操作完以后如果没有不想提交事务还可以回滚,truncate 和 drop 是 DDL 语句,操作完马上生效,不能回滚,打个比方,delete 是发微信说分手,后悔还可以撤回,truncate 和 drop 是直接扇耳光说滚,不能反悔。
3、执行的速度上,drop>truncate>delete,打个比方,drop 是神舟火箭,truncate 是和谐号动车,delete 是自行车。
CREATE DATABASE as4k
SHOW DATABASES
SHOW CREATE DATABASE as4k
HELP CREATE DATABASE
drop database as4k
HELP CREATE TABLE
SHOW CREATE TABLE student
SHOW TABLES
DESC student
DROP TABLE student
ALTER TABLE student RENAME stu
ALTER TABLE stu ADD age INT
ALTER TABLE stu ADD test VARCHAR(20), ADD qq INT
ALTER TABLE stu ADD classid VARCHAR(20) FIRST
ALTER TABLE stu ADD phone INT AFTER age
ALTER TABLE stu DROP qq
ALTER TABLE stu MODIFY sid VARCHAR(20)
ALTER TABLE stu CHANGE phone telphone CHAR(20)
INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2)
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9)
UPDATE student SET gender='f' WHERE sid=1
UPDATE student SET gender='f' WHERE 1=1
TRUNCATE TABLE student
OR DELETE FROM student
help truncate table
DELETE FROM student WHERE sid=3
此操作比较危险,而且不太必要GRANT ALL PRIVILEGES ON *.* TO as4k@'localhost' IDENTIFIED BY '123456'
GRANT ALL PRIVILEGES ON *.* TO as4k@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION
REVOKE SELECT ON *.* FROM root@'localhost'
SHOW GRANTS FOR as4k@'localhost'
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'
DROP USER 'as4k'@'localhost'
RENAME USER 'xudao'@'localhost' TO 'zengdao'@'localhost'
SET PASSWORD FOR 'as4k'@'localhost' = PASSWORD('123456')
SELECT 1 + 1
SELECT * FROM as4k
SELECT countrycode,district FROM city
SELECT * FROM city LIMIT 2,2
(编程语言可以利用此特性做分页)SELECT name,population FROM city WHERE countrycode='CHN'
SELECT name,population FROM city WHERE countrycode='CHN' AND district='heilongjiang'
SELECT * FROM city WHERE countrycode LIKE '%H%'
(与通配符匹配相似,不区分大小写)SELECT * FROM city ORDER BY col_name [ASC | DESC]
SELECT * FROM city WHERE population>=1410000
mysql < batch-file
mysql -e "source batch-file"
mysql -h host -u user -p < batch-file
简述SQL的执行过程(连接层——SQL层——存储引擎层)。
存储引擎层
客户端连接工具通过网络或本地socket连接到服务端(mysqld)
根据用户名,主机名,密码确认用户是否能成功登录
登录成功后,客户端发送SQL请求到服务端
服务端解析客户端请求的SQL语句,若果有语法错误直接报错
服务端验证根据权限表,验证用户是否有权限执行指定的SQL语句
如果要执行的SQL已经存放在缓存里,则直接返回
优化器对查询语句进行必要的优化
存储引擎与磁盘进行交互,将相关数据返回给用户
mysqld
The SQL daemon (that is, the MySQL server). To use client programs, mysqld must be running, because clients gain access to databases by connecting to the server.
mysqld_safe
A server startup script. mysqld_safe attempts to start mysqld.
mysql.server
A server startup script. This script is used on systems that use System V-style run directories containing scripts that start system services for particular run levels. It invokes mysqld_safe to start the MySQL server.
mysql_install_db
This program initializes the MySQL data directory, creates the mysql database and initializes its grant tables with default privileges, and sets up the InnoDB system tablespace. It is usually executed only once, when first installing MySQL on a system.
mysql_plugin
This program enables you to improve the security of your MySQL installation.
mysql_ssl_rsa_setup
This program creates the SSL certificate and key files and RSA key-pair files required to support secure connections, if those files are missing. Files created by mysql_ssl_rsa_setup can be used for secure connections using SSL or RSA.
mysql
The command-line tool for interactively entering SQL statements or executing them from a file in batch mode.
mysqladmin
A client that performs administrative operations, such as creating or dropping databases, reloading the grant tables, flushing tables to disk, and reopening log files. mysqladmin can also be used to retrieve version, process, and status information from the server.
查看正在使用的配置文件路径 mysqld --verbose --help
##################### 一份简单的配置文件示例 ####################################################################
[root@db01 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/3307/data
basedir=/usr/local/mysql
socket=/data/3307/mysql.sock
log_error=/data/3307/mysql.err
log-bin=/data/3307/mysql-bin
server_id=1
port=3307
##################### Option Files Read on Unix and Unix-Like Systems ######################################
File Name Purpose
/etc/my.cnf Global options
/etc/mysql/my.cnf Global options
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf Server-specific options (server only)
defaults-extra-file The file specified with --defaults-extra-file, if any
~/.my.cnf User-specific options
~/.mylogin.cnf User-specific login path options (clients only)
加上`--defaults-file`,加上这个参数以上配置文件均不读取。
如果配置冲突,读取顺序靠后的配置文件会覆盖前面的配置文件,也就是"后来者居上",这点与Shell环境变量类似。另外很多选项是可以直接在命令中指定的,命令行中的选项优先于所有配置文件。
##################### Option File Syntax #######################################################################
注释 #comment OR ;comment
##################### Here is a typical global option file: ######################################################
[group]
group is the name of the program or group for which you want to set options. After a group line, any option-setting lines apply to the named group until the end of the option file or another group line is given. Option group names are not case-sensitive.
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
[mysqldump]
quick
##################### Here is a typical user option file: ######################################################
[client]
# The following password will be sent to all standard MySQL clients
password="my password"
[mysql]
no-auto-rehash
connect_timeout=2
##################### Option File Inclusions #######################################################################
!include /home/mydir/myopt.cnf
!includedir /home/mydir
MySQL makes no guarantee about the order in which option files in the directory are read.
Any files to be found and included using the !includedir directive on Unix operating systems must have file names ending in .cnf
##################### 查看某个配置是否生效 ##############################################################################
mysql -p'As4k.top' -e "show variables" | grep "max_allowed_packet"
To determine the default command option and system variable values used by the server, execute this command:
shell> mysqld --verbose --help
To see the current system variable values actually used by the server as it runs, connect to it and execute this statement:
mysql> SHOW VARIABLES;
##################### 动态修改配置 ##########################################################################################
Many MySQL programs have internal variables that can be set at runtime using the SET statement.
mysql> SET GLOBAL max_allowed_packet=16M;
####################### 下划线和中划线是一样的 #################################################################################
If you like, underscores in a variable name can be specified as dashes. The following option groups are equivalent. Both set the size of the server's key buffer to 512MB:
[mysqld]
key_buffer_size=512M
[mysqld]
key-buffer-size=512M
####################### 未分类 #############################################################################################
Using System Variables
The MySQL server maintains many system variables that configure its operation.
Each system variable has a default value.
System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically while the server is running by means of the SET statement, which enables you to modify operation of the server without having to stop and restart it.
Many system variables are built in. System variables implemented by a server plugin are exposed when the plugin is installed and have names that begin with the plugin name. For example, the audit_log plugin implements a system variable named audit_log_policy.
There are two scopes in which system variables exist. Global variables affect the overall operation of the server. Session variables affect its operation for individual client connections. A given system variable can have both a global and a session value. Global and session system variables are related as follows:
At runtime, system variable names must be written using underscores, not dashes. The following examples briefly illustrate this syntax:
Set a global system variable:
SET GLOBAL max_connections = 1000;
SET @@GLOBAL.max_connections = 1000;
Set a session system variable:
SET SESSION sql_mode = 'TRADITIONAL';
SET @@SESSION.sql_mode = 'TRADITIONAL';
SET @@sql_mode = 'TRADITIONAL';
Some system variables can be enabled with the SET statement by setting them to ON or 1, or disabled by setting them to OFF or 0. However, to set such a variable on the command line or in an option file, you must set it to 1 or 0; setting it to ON or OFF will not work. For example, on the command line, --delay_key_write=1 works but --delay_key_write=ON does not.
##################################################################### Program Option Modifiers #################################
https://dev.mysql.com/doc/refman/5.7/en/option-modifiers.html
下面的3种用法等价:
--disable-column-names
--skip-column-names
--column-names=0
下面的3种用法等价:
--column-names
--enable-column-names
--column-names=1
The values ON, TRUE, OFF, and FALSE are also recognized for boolean options (not case-sensitive).
If an option is prefixed by --loose, a program does not exit with an error if it does not recognize the option, but instead issues only a warning:
shell> mysql --loose-no-such-option
mysql: WARNING: unknown option '--loose-no-such-option'
The --loose prefix can be useful when you run programs from multiple installations of MySQL on the same machine and list options in an option file. An option that may not be recognized by all versions of a program can be given using the --loose prefix (or loose in an option file). Versions of the program that recognize the option process it normally, and versions that do not recognize it issue a warning and ignore it.
Server Option, System Variable, and Status Variable Reference
https://dev.mysql.com/doc/refman/5.7/en/server-option-variable-reference.html
MySQL Server has several logs that can help you find out what activity is taking place.
Log Type Information Written to Log
Error log Problems encountered starting, running, or stopping mysqld
General query log Established client connections and statements received from clients
Binary log Statements that change data (also used for replication)
Relay log Data changes received from a replication master server
Slow query log Queries that took more than long_query_time seconds to execute
DDL log (metadata log) Metadata operations performed by DDL statements
By default, no logs are enabled
By default, the server writes files for all enabled logs in the data directory.
You can force the server to close and reopen the log files (or in some cases switch to a new log file) by flushing the logs. Log flushing occurs when you issue a FLUSH LOGS statement;
On Unix and Unix-like systems, mysqld uses the --log-error option to determine whether mysqld writes the error log to the console or a file, and, if to a file, the file name:
If --log-error is not given, mysqld writes the error log to the console.
If --log-error is given without naming a file, mysqld writes the error log to a file named host_name.err in the data directory.
If --log-error is given to name a file, mysqld writes the error log to that file (with an .err suffix added if the name has no suffix), located under the data directory unless an absolute path name is given to specify a different location.
If --log-error is given in an option file in a [mysqld], [server], or [mysqld_safe] section, mysqld_safe finds and uses the option, and passes it to mysqld.
It is common for Yum or APT package installations to configure an error log file location under /var/log with an option like log-error=/var/log/mysqld.log in a server configuration file. Removing the file name from the option causes the host_name.err file in the data directory to be used.
If the server writes the error log to the console, it sets the log_error system variable to stderr. Otherwise, the server writes the error log to a file and sets log_error to the file name.
############################### Error Log File Flushing and Renaming ###############################
mv host_name.err host_name.err-old
mysqladmin flush-logs
mv host_name.err-old backup-directory
MySQL Server Plugins
MySQL supports a plugin API that enables creation of server components. Plugins can be loaded at server startup, or loaded and unloaded at runtime without restarting the server.
############################### Installing and Uninstalling Plugins ###############################
Plugins installed with the INSTALL PLUGIN statement:
[mysqld]
plugin-load=myplugin=somepluglib.so
INSTALL PLUGIN myplugin SONAME 'somepluglib.so';
The plugin library file base name depends on your platform. Common suffixes are .so for Unix and Unix-like systems, .dll for Windows.
INSTALL PLUGIN also causes “permanent” plugin registration: The plugin is listed in the mysql.plugin table to ensure that the server loads it on subsequent restarts.
Many plugins can be loaded either at server startup or at runtime. However, if a plugin is designed such that it must be loaded and initialized during server startup, attempts to load it at runtime using INSTALL PLUGIN produce an error
To uninstall a plugin that currently is loaded at server startup with a plugin-loading option, use this procedure.
Remove any options related to the plugin from the my.cnf file.
Restart the server.
Plugins normally are installed using either a plugin-loading option at startup or with INSTALL PLUGIN at runtime, but not both. However, removing options for a plugin from the my.cnf file may not be sufficient to uninstall it if at some point INSTALL PLUGIN has also been used. If the plugin still appears in the output from INFORMATION_SCHEMA.PLUGINS or SHOW PLUGINS, use UNINSTALL PLUGIN to remove it from the mysql.plugin table. Then restart the server again.
############################### Obtaining Server Plugin Information ###############################
While a plugin is loaded, information about it is available from the INFORMATION_SCHEMA.PLUGINS table and the SHOW PLUGINS statement.
There are several ways to determine which plugins are installed in the server:
The INFORMATION_SCHEMA.PLUGINS table contains a row for each loaded plugin. Any that have a PLUGIN_LIBRARY value of NULL are built in and cannot be unloaded.
mysql> SELECT * FROM INFORMATION_SCHEMA.PLUGINS\G
The SHOW PLUGINS statement displays a row for each loaded plugin. Any that have a Library value of NULL are built in and cannot be unloaded.
mysql> SHOW PLUGINS;
+----------------------------+----------+--------------------+----------------------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+----------------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
.....
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
| validate_password | ACTIVE | VALIDATE PASSWORD | validate_password.so | GPL |
+----------------------------+----------+--------------------+----------------------+---------+
45 rows in set (0.00 sec)
The mysql.plugin table shows which plugins have been registered with INSTALL PLUGIN. The table contains only plugin names and library file names, so it does not provide as much information as the PLUGINS table or the SHOW PLUGINS statement.
############################### Controlling Plugin Activation State ###############################
If the server knows about a plugin when it starts (for example, because the plugin is named using a --plugin-load option or is registered in the mysql.plugin table), the server loads and enables the plugin by default. It is possible to control activation state for such a plugin using a --plugin_name[=activation_state] startup option, where plugin_name is the name of the plugin to affect, such as innodb, csv, or validate_password. As with other options, dashes and underscores are interchangeable in option names. Also, activation state values are not case-sensitive. For example, --my_plugin=ON and --my-plugin=on are equivalent.
--plugin_name=OFF
Tells the server to disable the plugin. This may not be possible for certain built-in plugins, such as mysql_native_password.
--plugin_name[=ON]
Tells the server to enable the plugin. (Specifying the option as --plugin_name without a value has the same effect.) If the plugin fails to initialize, the server runs with the plugin disabled.
Plugin activation states are visible in the LOAD_OPTION column of the INFORMATION_SCHEMA.PLUGINS table.
Suppose that CSV, BLACKHOLE, and ARCHIVE are built-in pluggable storage engines and that you want the server to load them at startup, subject to these conditions: The server is permitted to run if CSV initialization fails, must require that BLACKHOLE initialization succeeds, and should disable ARCHIVE. To accomplish that, use these lines in an option file:
[mysqld]
csv=ON
blackhole=FORCE
archive=OFF
The --enable-plugin_name option format is a synonym for --plugin_name=ON. The --disable-plugin_name and --skip-plugin_name option formats are synonyms for --plugin_name=OFF.
############################### 未分类 ################################################################################
A password-validation plugin implements password strength policies and assesses the strength of potential passwords.
https://dev.mysql.com/doc/refman/5.7/en/validate-password.html
Group Replication enables you to create a highly available distributed MySQL service across a group of MySQL server instances, with data consistency, conflict detection and resolution, and group membership services all built-in.
https://dev.mysql.com/doc/refman/5.7/en/group-replication.html
CREATE USER 'xudao'@'127.0.0.1';
CREATE USER 'xudao_ugly'@'127.0.0.1' IDENTIFIED BY '123';
SELECT USER,HOST FROM mysql.user;
SHOW GRANTS FOR xudao_ugly@127.0.0.1;
'用户名'@'主机域'
10.0.0.%
10.0.%.%
10.0.0.0/255.255.255.0
######################## 使用grant直接创建用户 ######################################################
GRANT SELECT,UPDATE,DROP,DELETE ON *.* TO xudao_old@127.0.0.1 IDENTIFIED BY '123';
######################## 删除用户 ##############################################################
drop user xudao@'127.0.0.1';
######################## 修改用户密码 ############################################################
grant update alter set mysqladmin 这五种方式都可以修改用户密码。
注意要修改密码,需要当前用户具有更改其它用户密码的权限才行。
**1** GRANT ALL ON *.* TO xudao_old@127.0.0.1 IDENTIFIED BY '1234';
**2** UPDATE mysql.user SET PASSWORD=PASSWORD('5678') WHERE USER='xudao_old' AND HOST='127.0.0.1';
**3** alter 暂时不讲
**4** SET PASSWORD=PASSWORD('5678'); 更改当前登录用户的密码
**5** mysqladmin -h127.0.0.1 -uxudao_old -p5678 PASSWORD '123'; 在SHELL中直接修改。只能更改本地localhost主机用户的密码,不可用更改远端连接用户的密码,127.0.0.1主机也不可以更改。
########################################## 忘记root密码后如何恢复 ##########################################
1 先跳过授权表,启动MySQL --skip-grant-tables (安装起见,跳过网络) --skip-networking
2 登录MySQL,直接登录敲回车,无需输入密码
3 使用upate命令修改密码
4 刷新授权表 flush privileges;
mysql> update mysql.user set password=PASSWORD('root') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
########################################## 用户权限 ###########################################################
GRANT ALL PRIVILEGES ON *.* TO as4k@'10.0.0.%' IDENTIFIED BY '123';
权限 作用对象 归属 密码
ALL PRIVILEGES 与 ALL 功能是一样的。相当于简写。
单库 单表 所有库所有表 授权可以精确到字段。
grant select(host) on mysql.user to xudao_5@'localhost' identified by '123';
官方手册B.5.3.2 How to Reset the Root Password
对root密码忘记如何重置,有详细介绍。
1 关闭mysqld服务
shell> pkill mysql
shell> netstat -lntup | grep mysql
2 创建初始化密码配置文件
shell> cat /tmp/mysql-init
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
shell> chown mysql:mysql /tmp/mysql-init
3 用上面的配置文件启动mysqld服务
shell> mysqld --user=mysql --init-file=/tmp/mysql-init &
4 此时root用户密码已被修改为123456
,可重启mysqld进行测试。
假设我们不是简单的忘记,’root’@‘localhost’ 的密码,而且直接手残删除了root账号,也就是SELECT user,host from mysql.user
已经看不见root账号。假设当前会话还没退出,则我们直接重新创建root账号并授权即可,可是我们又二次手残已经退出当前会话,即使这样我们还可以通过下面的方式恢复root账号。
1 重新启动mysqld,跳过授权表,跳过网络
shell> pkill mysql
shell> mysqld_safe --skip-grant-tables --skip-networking &
跳过授权表则客户端登录MySQL Server无需密码,跳过网络则不允许任何远程客户端登录本机MySQL Server,这是出于安全方面的考虑,一旦跳过网络会发现本机根本没有3306端口。
2 直接登录MySQL Server,刷新权限表
shell> mysql
mysql> FLUSH PRIVILEGES;
如果不刷新授权表,则GRANT
等授权命令无法使用。先关闭再刷新开启,由于我们已经处于当前登录会话,不会自动退出。
3 重新创建root用户,权限打满
mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
mysql> SHOW GRANTS FOR 'root'@'localhost';
mysql> SELECT * FROM mysql.user\G
4 重新正常启动mysqld,使用新密码(123456)连接
shell> pkill mysql
shell> /etc/init.d/mysqld start
shell> mysql -uroot -p123456
mysql> \s
正常root密码忘记,root账号还在,建议使用方法1即可,方法2也可以直接使用INSERT
的方法,往表中插入一行root账号的信息。
SQL pattern matching enables you to use _ to match any single character and % to match an arbitrary
number of characters (including zero characters).
% 匹配任意多个字符(包括零个)
_ 匹配任意单个字母
1) username@'主机域'
2)主机域:可以理解为是MySQL登陆的白名单
3)主机域格式:
10.0.0.51
'10.0.0.5%'
'10.0.0.%'
'10.0.%.%'
'10.%.%.%'
'%'
'db01'
'10.0.0.51/255.255.255.0'
0 多实例的启动和关闭
关闭
pkill mysql
启动
mysqld_safe --defaults-file=/data/3307/my.cnf &
mysqld_safe --defaults-file=/data/3308/my.cnf &
mysqld_safe --defaults-file=/data/3309/my.cnf &
mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"
1 进入3307示例,导入world.sql数据库
shell> mysqld_safe --defaults-file=/data/3307/my.cnf &
shell> mysql -S /data/3307/mysql.sock
mysql> source /root/world.sql
mysql> select * from world.city limit 10;
+----+----------------+-------------+---------------+------------+
| ID | Name | CountryCode | District | Population |
+----+----------------+-------------+---------------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
| 6 | Rotterdam | NLD | Zuid-Holland | 593321 |
| 7 | Haag | NLD | Zuid-Holland | 440900 |
| 8 | Utrecht | NLD | Utrecht | 234323 |
| 9 | Eindhoven | NLD | Noord-Brabant | 201843 |
| 10 | Tilburg | NLD | Noord-Brabant | 193238 |
+----+----------------+-------------+---------------+------------+
10 rows in set (0.00 sec)
2 把3307实例world数据文件复制到3308实例
shell> mysqld_safe --defaults-file=/data/3308/my.cnf &
shell> cp -a /data/3307/data/world /data/3308/data
shell> mysql -S /data/3308/mysql.sock
此时登录到3308实例上,可以看到world库里的表,但是不能使用,会报找不到表错误,如下:
mysql> select * from world.city limit 10;
ERROR 1146 (42S02): Table 'world.city' doesn't exist
3 以city表为例,在3308实例上创建新表new_city
新表的表结构和原表是一样的,这套建表语句在真实环境中我们需要找开发要,现在模拟环境,我们可以登录到3307实例,使用show create table city
来得到
由于外键的特殊限制,我们需要把建表语句中的外键删除。
mysql> show create table world.city\G;
*************************** 1. row ***************************
Table: city
Create Table: CREATE TABLE `city` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
修改上述语句如下:
USE world;
CREATE TABLE `new_city` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1;
4 删除3308实例,new_city的表空间
shell> ALTER TABLE new_city DISCARD TABLESPACE;
实质就是将物理文件new_city.ibd
删除之。
5 将底层的物理文件city.ibd拷贝成new_city.ibd
shell> cd /data/3308/data/world/
shell> ls -lh
total 1012K
-rw-rw---- 1 mysql mysql 8.6K Nov 30 20:28 city.frm
-rw-rw---- 1 mysql mysql 576K Nov 30 20:28 city.ibd
-rw-rw---- 1 mysql mysql 9.0K Nov 30 20:28 country.frm
-rw-rw---- 1 mysql mysql 160K Nov 30 20:28 country.ibd
-rw-rw---- 1 mysql mysql 8.5K Nov 30 20:28 countrylanguage.frm
-rw-rw---- 1 mysql mysql 224K Nov 30 20:28 countrylanguage.ibd
-rw-rw---- 1 mysql mysql 65 Nov 30 20:28 db.opt
-rw-rw---- 1 mysql mysql 8.6K Nov 30 20:44 new_city.frm
shell> cp -a city.ibd new_city.ibd
Note: *.ibd
是数据和索引文件,*.frm
表的结构定义文件
至此表数据已经还原完毕,即new_city.ibd
和city.ibd
数据是一样的。如果此时我们去查询new_city表的内容,会提示表空间已丢失,也就是表结构和表空间关联不上,需要我们重建表结构。
mysql> select * from new_city;
ERROR 1814 (HY000): Tablespace has been discarded for table 'new_city'
下面就是重建表结构。
6 连接3308实例,导入新的表空间
mysql> ALTER TABLE new_city IMPORT TABLESPACE;
7 在3308实例上验证是否可以查询数据
mysql> SELECT COUNT(*) FROM new_city;
+----------+
| COUNT(*) |
+----------+
| 4079 |
+----------+
1 row in set (0.00 sec)
8 删除原有表,物理上的表结构和表空间
shell> cd /data/3308/data/world
shell> rm -f city.frm city.ibd
9 在3308实例上修改新表名为旧表
mysql> ALTER TABLE new_city RENAME city;
至此,修复表结构操作完毕。
show charset
可以看到全部字符集show collation
可以看到全部的校对规则SET NAMES 'utf8'
CREATE DATABASE mydb CHARACTER SET utf8 COLLATE utf8_general_ci
CREATE TABLE test (id int(4)) CHARSET utf8
mysql -e 'help create table' | grep charset
ALTER DATABASE as4k CHARACTER SET utf8 COLLATE utf8_general_ci
select t1.sname,t2.mark from t1,t2 where t1.sid=t2.sid and t1.sname='zhang3'
SELECT city.name,city.countrycode,country.name FROM city,country WHERE city.countrycode=country.code AND city.population<100
SELECT city.name,city.countrycode,countrylanguage.language,city.population FROM city NATURAL JOIN countrylanguage WHERE population > 1000000 ORDER BY population;
SELECT city.name,city.countrycode,country.name FROM city JOIN country ON city.countrycode=country.code WHERE city.population<100
SELECT city.name,city.countrycode,country.name FROM city LEFT JOIN country ON city.countrycode=country.code AND city.population<100
SELECT city.name,city.countrycode,country.name FROM city RIGHT JOIN country ON city.countrycode=country.code AND city.population<100
SELECT * FROM city WHERE countrycode='CHN' UNION ALL SELECT * FROM city WHERE countrycode='USA' LIMIT 10
ALTER TABLE t2 MODIFY id INT NOT NULL PRIMARY KEY
ALTER TABLE t2 DROP PRIMARY KEY
ALTER TABLE t2 ADD UNIQUE KEY uni_age(age)
ALTER TABLE t2 DROP KEY uni_age
ALTER TABLE test ADD INDEX index_name(NAME)
CREATE INDEX index_name ON test(NAME)
ALTER TABLE test DROP KEY index_name
DESC tb2
SHOW INDEX FROM tb_name
ALTER TABLE test ADD INDEX idx_name(NAME(10))
CREATE TABLE people (id INT,NAME VARCHAR(20),age TINYINT,money INT ,gender ENUM('m','f'))
ALTER TABLE people ADD INDEX idx_gam(gender,age,money)
SELECT COUNT(*) FROM city
SELECT COUNT(DISTINCT NAME) FROM city
EXPLAIN SELECT NAME,countrycode FROM city WHERE id=1
EXPLAIN | DESCRIBE | DESC
是互为别名的关系ALTER TABLE city DROP INDEX idx_pop
SHOW ENGINES
ORSELECT * FROM INFORMATION_SCHEMA.ENGINES
SELECT table_schema,table_name,engine FROM information_schema.tables WHERE ENGINE='innodb'
SELECT table_schema,table_name,engine FROM information_schema.tables WHERE ENGINE='myisam'
SELECT @@default_storage_engine
USE db_name; SHOW TABLE STATUS LIKE 'tb_name'\G
SET @@storage_engine=<Storage Engine>
CREATE TABLE tb1 (col1 INT) ENGINE = <Storage Engine>
./data/ibdata1
SHOW VARIABLES LIKE '%path%'
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend
autoextend
必须应用在最后一个表空间上./data/db_name/tb_name.ibd
SHOW VARIABLES LIKE '%per_table%'
begin; SQL1;SQL2; ... SQLN; commit;
begin; SQL1;SQL2; ... SQLN; rollback;
SHOW VARIABLES LIKE 'autocommit'
SET autocommit=0
autocommit=0
ib_logfile0 ib_logfile1 ...
ibdata1
--log-error[=file_name]
hostname.err
show variables like 'log_error'
--log[=file_name]
SET GLOBAL general_log ON
log-bin=mysql-bin
mysql-bin.000001 mysql-bin.000002 ...
show binary logs
show master status
binlog_format=statement
binlog_format=row
show binlog events in 'mysql-bin.000013'
mysqlbinlog --base64-output=decode-rows -vvv mysql-bin.000013
set sql_log_bin=0
flush logs
SET GLOBAL expire_logs_days = 7
PURGE BINARY LOGS BEFORE now() - INTERVAL 3 day
PURGE BINARY LOGS TO 'mysql-bin.000010'
reset master
hostname-slow.log
slow_query_log = 1
slow_query_log_file=/usr/local/mysql/data/slow.log
long_query_time=0.05
log_queries_not_using_indexes
mysqldumpslow -s sort_type -t N log_file
mysqldumpslow -s c -t 10 /usr/local/mysql/data/slow.log
yum install percona-toolkit-3.0.11-1.el6.x86_64.rpm
pt-query-digest /usr/local/mysql/data/slow.log
-A, --all-databases
全库备份
mysqldump -uroot -ppwd -A > /backup/full.sql
--flush-logs, -F
在备份时自动刷新binlog(不怎么常用)--master-data=2
备份时加入change master语句,0没有,1不注释,2注释-R, --routines
备份存储过程和函数数据--triggers
备份触发器数据]-x
锁表备份(MyISAM温备份)--single-transaction
快照备份mysqldump -uroot -ppwd -A -R --triggers --master-data=2 –single-transaction | gzip > /backup/full.sql.gz
innobackupex --user=root --socket=/tmp/mysql.sock --no-timestamp /backup/full