• Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
  • Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
home/Knowledge Base/MariaDB/MariaDB – Drop Database
Popular Search:Oracle, SQL Server, MongoDB

MariaDB – Drop Database

79 views 0 June 1, 2020 admin

Creation or deletion of databases in MariaDB requires privileges, typically, only given to root users or admins. Under these accounts, you have two options for deleting a database: the mysqladmin binary and a PHP script.

Note that deleted databases are irrecoverable, so exercise care in performing this operation. Furthermore, PHP scripts used for deletion do not prompt you with a confirmation before the deletion.

mysqladmin Binary

The following example demonstrates how to use the mysqladmin binary to delete an existing database:

[root@host]# mysqladmin -u root -p drop PRODUCTS
Enter password:******
mysql> DROP PRODUCTS
ERROR 1008 (HY000): Can't drop database 'PRODUCTS'; database doesn't exist

PHP Drop Database Script

PHP employs the mysql_query function in deleting MariaDB databases. The function uses
two parameters, one optional, and returns either a value of “true” when successful, or
“false” when not. y

Syntax

Review the following drop database script syntax:

bool mysql_query( sql, connection );

The description of the parameters is given below:

Parameter Description
sql This required parameter consists of the SQL query needed to perform the operation.
connection When not specified, this optional parameter uses the most recent connection used.

Try the following example code for deleting a database:

<html>
<head>
<title>Delete a MariaDB Database</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = 'DROP DATABASE PRODUCTS';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not delete database: ' . mysql_error());
}
echo "Database PRODUCTS deleted successfully\n";
mysql_close($conn);
?>
</body>
</html>

On successful deletion, you will see the following output:

mysql> Database PRODUCTS deleted successfully

Was this helpful?

Yes  No
Related Articles
  • MariaDB – Where Clause
  • MariaDB – Select Query
  • MariaDB – Insert Query
  • MariaDB – Drop Tables
  • MariaDB – Create Tables
  • MariaDB – Data Types
Leave A Comment Cancel reply

MariaDB
  • MariaDB – Drop Database
  • MariaDB – Where Clause
  • MariaDB – Select Query
  • MariaDB – Insert Query
  • MariaDB – Drop Tables
  • MariaDB – Create Tables
View All 14  
Popular Articles
  • Upgrade Oracle Database from 11.2.0.3 to 12.1.0.2
  • Upgrading MariaDB on Windows
  • Oracle DBA Basic Interview Questions Part A
  • Purging Oracle Sysaux Tablespace
  • Client – Server Architecture
KB Categories
  • Oracle Database
    • Oracle RAC
    • Oracle ASM
    • Oracle GoldenGate
    • Oracle Tuning
    • Oracle 11g Database
    • Oracle Database Upgrade
    • Oracle 12c Database
    • ALL KB Oracle
    • Oracle 18c Database
    • Oracle Standby Database
  • MongoDB
  • MS SQL Server
  • MySQL
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • MariaDB
Database Organization

Database Organization (DB ORG) is knowledge base for DBA to learn and execute the fundamental of different databases under one website. DB ORG is a non-profit initiative. ORACLE, MS SQL Server, MongoDB, MariaDB, Couchbase

Join Our Community
  • KnowledgeBase
  • Documentation
  • Troubleshoot
  • FAQ
Information Links
  • About DBOrg
  • Licenses
  • Terms
  • Privacy Policy
Contact Us
    DB ORG - Database Administration,
    Knowledge Base for DBA
    Mail: support@databaseorg.com
    WhatsApp: (+91) 9306440957
    Monday to Friday: EST - 11:30 AM to 06:30 PM (IST - 9:00 PM to 4:00 AM)
  • © 2023 Database Organization - DB ORG. All Rights Reserved.

Popular Search:Oracle, SQL Server, MongoDB

WhatsApp DB Org