How To Drop an Existing Database


How To Drop an Existing Database? - MySQL FAQs - PHP Connections and Query Execution



If want to drop an existing database from the MySQL server, you can use the DROP DATABASE statement. Here is a good example of dropping an existing database:

  $con = mysql_connect('localhost:8888', 'dev', 'iyf');
  $sql = 'DROP DATABASE fyi';
  if (mysql_query($sql, $con)) {
    print("Database fyi dropped.\n");
  } else {
    print("Database drop failed with error:\n");
    print(mysql_errno($con).": ".mysql_error($con)."\n");

If you run this script, you will get something like this, if "dev" does not have privilege to drop database:

Database drop failed with error:
1044: Access denied for user 'dev'@'%' to database 'fyi'

2007-05-10, 4696👍, 0💬