MySQL 历史显示了很多\040

问题描述

当我试图查看 MysqL 的历史时 - 我看到了这个

cat ~/.MysqL_history

我明白了:

└──  cat ~/.MysqL_history
_HiStOrY_V2_
exit
GRANT\040ALL\040PRIVILEGES\040ON\040*\040.\040*\040TO\040'jada'@'localhost';
FLUSH\040PRIVILEGES;
select\040User,Host\040from\040MysqL.user;
exit
select\040User,Host\040from\040MysqL.user;
GRANT\040ALL\040PRIVILEGES\040ON\040*\040.\040*\040TO\040'jada'@'localhost';
FLUSH\040PRIVILEGES;
select\040User,Host\040from\040MysqL.user;
exit
drop\040database\app;\040
show\040databases;\040
create\040database\app;\040
exit
show\040databases;\040
use\app;\040
select\040*\040from\040users;\040
exit
use\app;\040
select\040*\040from\040users;\040
exit
select\040User,Host\040from\040MysqL.user;
exit
select\040*\040from\040users;
show\040databases;\040
use\app\040;\040
select\040*\040from\040users;
DELETE\040FROM\040table_name\040WHERE\040condition;
DELETE\040FROM\040users\040WHERE\040id\040=\0402;
select\040*\040from\040users;
history
show\040history;
exit

我看到一堆\040

如何在 bash 中查看像常规历史记录那样干净的历史记录?

我已经尝试了 5 个虚拟机。结果一样。一直以来。

解决方法

我记得是 mysql 客户端 https://bugs.mysql.com/bug.php?id=68925 上的旧错误 尝试更新它

,
sed 's/\\040/ /g' < .mysql_history

这只修复空格;我不知道问题的严重程度。

\0xx 是八进制转义序列。 40space 的八进制。

,

这是的常见工作:

perl -pe 's/\\([0-7]{1,3})/chr oct $1/eg' <.mysql_history

这将解析八进制表示(不仅仅是空格)。

演示/测试:

perl -pe 's/\\([0-7]{1,3})/chr oct $1/eg' <<<"SELECT\040\042String\042;"
SELECT "String";

但这可以通过

一行一行,主要是如果一行需要,你可以

echo -e "GRANT\040ALL\040PRIVILEGES\040ON\040*\040.\040*\040TO\040'jada'@'localhost';"
GRANT ALL PRIVILEGES ON * . * TO 'jada'@'localhost';

或更好,使用 :

printf %b\\n "GRANT\040ALL\040PRIVILEGES\040ON\040*\040.\040*\040TO\040'jada'@'localhost';"
GRANT ALL PRIVILEGES ON * . * TO 'jada'@'localhost';

当然,你可以遍历整个文件:

while read -r line ;do
    printf '%b\n' "$line"
done <.mysql_history
,

您可以使用 sed 命令简单地用空格字符替换 \040 并为其定义别名,这样您就可以简单地调用别名而不是重复完整的命令:Alias mysqlh for mysql history

$ alias mysqlh="cat ~/.mysql_history | sed 's/\\\040/ /g'"
$ mysqlh
_HiStOrY_V2_
exit
GRANT ALL PRIVILEGES ON * . * TO 'jada'@'localhost';
FLUSH PRIVILEGES;
select User,Host from mysql.user;
exit
select User,Host from mysql.user;
GRANT ALL PRIVILEGES ON * . * TO 'jada'@'localhost';
FLUSH PRIVILEGES;
select User,Host from mysql.user;
exit
drop database\app;
show databases;
create database\app;
exit
show databases;
use\app;
select * from users;
exit
use\app;
select * from users;
exit
select User,Host from mysql.user;
exit
select * from users;
show databases;
use\app ;
select * from users;
DELETE FROM table_name WHERE condition;
DELETE FROM users WHERE id = 2;
select * from users;
history
show history;
exit