MySQL 是目前世界上最流行的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),廣泛應(yīng)用于Web應(yīng)用開(kāi)發(fā)以及企業(yè)信息化等領(lǐng)域。但在MySQL 的使用過(guò)程中,難免會(huì)遇到一些問(wèn)題,例如“數(shù)據(jù)庫(kù)不存在”的情況。
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 205360 Server version: 5.7.24-0ubuntu0.18.04.1 (Ubuntu) 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 | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec) mysql>use mydatabase; ERROR 1049 (42000): Unknown database 'mydatabase'
在MySQL 執(zhí)行“use mydatabase;”這行命令時(shí),遇到了“ERROR 1049 (42000): Unknown database 'mydatabase'”的報(bào)錯(cuò)信息,意思是“mydatabase”這個(gè)數(shù)據(jù)庫(kù)不存在。產(chǎn)生這種情況的原因可能是數(shù)據(jù)庫(kù)名稱拼寫錯(cuò)誤、該數(shù)據(jù)庫(kù)還未創(chuàng)建等。
為避免這種錯(cuò)誤的發(fā)生,可以在執(zhí)行“use xxx;”命令前,先通過(guò)“show databases;”命令查看所有的數(shù)據(jù)庫(kù),并確認(rèn)目標(biāo)數(shù)據(jù)庫(kù)是否存在。
mysql>show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql>use mydatabase; ERROR 1049 (42000): Unknown database 'mydatabase' mysql>use mydb; Database changed
通過(guò)先使用“show databases;”檢查數(shù)據(jù)庫(kù)的存在,然后使用正確的數(shù)據(jù)庫(kù)名稱,就可以避免“數(shù)據(jù)庫(kù)不存在”的錯(cuò)誤了。