暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysql基础 show warnings 查看警告信息

  •        OS : Ubuntu 18.04.1 LTS
  •        DBMS : mysql 8.0.12

示例

stu@Ubuntu:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 85 Server version: 8.0.12 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | db_herbal_medicine | | employees | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) mysql> create database db_herbal_medicine; ERROR 1007 (HY000): Can't create database 'db_herbal_medicine'; database exists mysql> create database if not exists db_herbal_medicine; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> show warnings; +-------+------+-------------------------------------------------------------+ | Level | Code | Message | +-------+------+-------------------------------------------------------------+ | Note | 1007 | Can't create database 'db_herbal_medicine'; database exists | +-------+------+-------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> exit Bye stu@Ubuntu:~$

扩展

  • 在[2]中提到的:注意:warnings只记录上一次执行的提示,如果你在出现一个warning之后,再执行了一次正常的查询,如select 1/0; 得到一个warning,然后又执行了select now();这次没有告警,你再做show warnings也是看不到告警信息了。
  • 基于MySQL8,测试结果如下所示。
stu@Ubuntu:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 86 Server version: 8.0.12 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database if not exists db_herbal_medicine; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-10-21 20:40:22 | +---------------------+ 1 row in set (0.00 sec) mysql> show warnings; Empty set (0.00 sec) mysql> exit Bye stu@Ubuntu:~$

参考资料

  1. mysql 查看警告
  2. 在mysql如何查看sql执行的warning相关信息

学习资源


欢迎各位同学一起来交流学习心得!

最后修改时间:2021-12-16 18:00:43
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论