【问题标题】:MySQL history show a lot of \040MySQL历史显示很多\040
【发布时间】:2021-07-10 16:54:32
【问题描述】:

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

猫~/.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;
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;
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 台虚拟机。结果相同。无时无刻不在。

【问题讨论】:

  • \040 是空格字符。
  • 我没有看到类似的东西。 type cat 显示什么?
  • 你运行的是什么版本的mysql
  • @Barmar 我在Server version: 8.0.20-0ubuntu0.19.10.1
  • 这是客户端问题,不是服务器问题。但也许他们改变了历史文件的格式(我还在使用 5.x)。

标签: mysql bash shell history


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    sed 's/\\040/ /g' < .mysql_history
    

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

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

    【讨论】:

      【解决方案3】:

      这是的常见工作:

      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
      

      【讨论】:

        【解决方案4】:

        您可以使用 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;
        GRANT ALL PRIVILEGES ON * . * TO 'jada'@'localhost';
        FLUSH PRIVILEGES;
        select User,Host from mysql.user;
        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-06-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-07
          • 1970-01-01
          • 2014-02-26
          • 1970-01-01
          相关资源
          最近更新 更多