Devdit
 

ERROR 1046 (3D000): No database selected คือ วิธีแก้ไข

1.3K

ลองรันคำสั่ง SHOW TABLES ของภาษา SQL เพื่อแสดงตารางออกสู่หน้าจอ แต่ไม่สำเร็จขึ้นข้อความ Error ว่า ERROR 1046 (3D000): No database selected แบบนี้ต้องแก้ไขอย่างไร

C:\Users\admin>mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.4.19-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW TABLES;
ERROR 1046 (3D000): No database selected

 

วิธีแก้ไข

กรณีต้องการใช้คำสั่ง SHOW TABLES เพื่แสดงรายการตาราง ต้องเลือก หรือเข้าใช้งานฐานข้อมูลก่อนด้วยคำสั่ง SHOW DATABASES และเลือกฐานข้อมูลด้วยคำสั่ง USE สามารถเขียนคำสั่งได้ดังนี้

 SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| db_example         |
| db_mycompany       |
| db_test            |
| devdit             |
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
+--------------------+
8 rows in set (0.002 sec)
MariaDB [(none)]> use db_example
Database changed
MariaDB [db_example]> SHOW TABLES;
+----------------------+
| Tables_in_db_example |
+----------------------+
| book                 |
| test                 |
+----------------------+
2 rows in set (0.001 sec)
แก้ไข 2 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ