Create Database Using mysqladmin
You would need special privileges to make or to delete a MySQL database. So assuming you’ve got access to the root user, you’ll create any database using the MySQL mysqladmin binary.
You can create a MySQL database by using the MySQL Command Line Client. Here is a simple example to create a database called “LEARNING”
1 2 |
[root@host]# mysqladmin -u root -p create learning Enter password:****** |
Create Database Using PHP
Let’s take an example to create a database name “LEARNING” with PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php //Your MySQL databse settings $servername = "localhost"; $username = "root"; $password = "root"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Create database $sql = "CREATE DATABASE LEARNING"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?> |
What is Next?
In the next section, you will learn how to drop a database in MySQL.
* Please do let us know your views on this article and what type of articles would you are interested to read.
Widget not in any sidebars
