1、MySQL版本
5.7.14-log
2、问题分析
mysqldump -uxxx -pxxx db_nale
一般来讲上述命令主要是用于MySQL的逻辑备份,用来备份某个数据的全部表,但是我在执行该命令的时候却发生报错。报错如下:
Couldn't execute 'SHOW VARIABLES LIKE 'gtid\_mode''
[root@bak tmp]# mysqldump -uroot -p123 --databases test
mysqldump: [Warning] Using a password on the command line interface can be insecure.
-- MySQL dump 10.13 Distrib 5.7.14, for Linux (x86_64)
--
-- Host: localhost Database: test
-- ------------------------------------------------------
-- Server version 5.7.14-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'gtid\_mode'': Unknown error 1146 (1146)
经过万能的百度,大家都说需要添加【--set-gtid-purged=OFF】参数。该参数是由于GTID导致的,mysqldump会试图去查询这个系统变量,具体原因还未查清楚,但是我添加该参数后发现仍有报错,报错如下:
Couldn't execute 'SHOW VARIABLES LIKE 'ndbinfo\_version''
[root@bak tmp]# mysqldump -uroot -p123 --databases test --set-gtid-purged=OFF
Warning: Using a password on the command line interface can be insecure.
-- MySQL dump 10.13 Distrib 5.6.26, for Linux (x86_64)
--
-- Host: localhost Database: test
-- ------------------------------------------------------
-- Server version 5.7.14-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'ndbinfo\_version'': Unknown error 1146 (1146)
emmm....问题仍然没有解决,说明问题不是GTID的问题。
最后在找到了一个解决方法,有好心人回复说,这是由于MySQL服务器升级的原因导致的,所以我们应该升级MySQL服务。
[root@bak tmp]# mysql_upgrade -u root -p123 --force
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
.....
.....
zabbix.users OK
zabbix.users_groups OK
zabbix.usrgrp OK
zabbix.valuemaps OK
Upgrade process completed successfully.
Checking if update is needed.
在升级完成MySQL服务之后重启MySQL,然后重新执行mysqldump命令。
[root@bak ~]# mysqldump -uroot -p123 --databases test >a.sql
Warning: Using a password on the command line interface can be insecure.
问题解决~
具体参考如下:
https://stackoverflow.com/questions/33270703/error-1142-select-command-denied-on-session-variables-table-with-mysqldump