Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

ลบฐานข้อมูลด้วย mysqladmin drop

คำสั่งลบ Database

[root@host]# mysqladmin -u root -p drop db_name
Enter password:******

ตัวอย่าง: ลบ database TUTORIALS

[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'TUTORIALS' database [y/N] y
Database "TUTORIALS" dropped

ขั้นตอน

  1. รันคำสั่งพร้อม -p (prompt password)
  2. ใส่รหัสผ่าน root
  3. ยืนยันด้วย y
  4. Database ถูกลบถาวร

ข้อควรระวัง

  • ต้องมีสิทธิ์ DROP (มักเป็น root หรือ admin)
  • ข้อมูลหายถาวร ไม่สามารถ Undo ได้
  • ควร Backup ก่อนลบ (mysqldump)
  • Production ควรมีกระบวนการอนุมัติ

คำสั่ง SQL เทียบเท่า

DROP DATABASE db_name;
-- ต้อง Login MySQL ก่อน: mysql -u root -p

mysqladmin อื่นๆ

  • create db_name - สร้าง DB
  • ping - ตรวจสอบ Server
  • status - ดูสถานะ
  • version - ดูเวอร์ชัน
  • shutdown - ปิด Server