1. 程式人生 > >mysql8基礎 show warnings 檢視警告資訊

mysql8基礎 show warnings 檢視警告資訊

資料,資料,命根就在資料 ! 操作資料庫時,一定要謹慎小心。師萬物 的程式碼看看就好,要有自己的判斷。遇到抉擇,要不恥上下問。

example

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:~$

more knowledge

  • 在[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:~$ 

reference

resource

MySQL是一個關係型資料庫管理系統,目前是開源的(2018-10)。
許可權明確,引擎與字符集等選擇恰當,命名規範。
MariaDB,Redis,MongoDB,PostgreSQL,Hive,HBase等,多作了解,拓寬心量。
Workbench,phpMyAdmin,Navicat等圖形化管理工具,豫兮若冬涉川。