- MariaDB - Useful Functions
- MariaDB - Backup Loading Methods
- MariaDB - Backup Methods
- MariaDB - SQL Injection Protection
- MariaDB - Managing Duplicates
- MariaDB - Sequences
- MariaDB - Table Cloning
- MariaDB - Temporary Tables
- Indexes & Statistics Tables
- MariaDB - Alter Command
- MariaDB - Transactions
- MariaDB - Regular Expression
- MariaDB - Null Values
- MariaDB - Join
- MariaDB - Order By Clause
- MariaDB - Like Clause
- MariaDB - Delete Query
- MariaDB - Update Query
- MariaDB - Where Clause
- MariaDB - Select Query
- MariaDB - Insert Query
- MariaDB - Drop Tables
- MariaDB - Create Tables
- MariaDB - Data Types
- MariaDB - Select Database
- MariaDB - Drop Database
- MariaDB - Create Database
- MariaDB - Connection
- MariaDB - PHP Syntax
- MariaDB - Administration
- MariaDB - Installation
- MariaDB - Introduction
- MariaDB - Home
MariaDB Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MariaDB - Create Database
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 creating a database − the mysqladmin binary and a PHP script.
mysqladmin binary
The following example demonstrates the use of the mysqladmin binary in creating a database with the name Products −
[root@host]# mysqladmin -u root -p create PRODUCTS Enter password:******
PHP Create Database Script
PHP employs the mysql_query function in creating a MariaDB database. The function uses two parameters, one optional, and returns either a value of “true” when successful, or “false” when not.
Syntax
Review the following create database script syntax −
bool mysql_query( sql, connection );
The description of the parameters is given below −
S.No | Parameter & Description |
---|---|
1 |
sql This required parameter consists of the SQL query needed to perform the operation. |
2 |
connection When not specified, this optional parameter uses the most recent connection used. |
Try the following example code for creating a database −
<html> <head> <title>Create 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 = CREATE DATABASE PRODUCTS ; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die( Could not create database: . mysql_error()); } echo "Database PRODUCTS created successfully "; mysql_close($conn); ?> </body> </html>
On successful deletion, you will see the following output −
mysql> Database PRODUCTS created successfully mysql> SHOW DATABASES; +-----------------------+ | Database | +-----------------------+ | PRODUCTS | +-----------------------+Advertisements