Create Database using MySqladmin

0
56

You can create any database using MySQL mysqladmin binary.Either it is a local server made by using Xamp or Online servers.This way you can have a database ready.

Example:

A simple example to Show you as how to  create database named as “Database tutorials”:

[root@host]# mysqladmin -u root -p create Database tutorials

Enter password:*****

The above-given code will create a MySQL database  “Database Tutorials”.

 

Create Database using PHP Script:

PHP uses the mysql_query function in order create or delete a MySQL database.

Syntax:

bool mysql_query( SQL, connection );

Commands Details
sql Required – SQL query in order to create or delete a MySQL database
connection “Optional” – if it is not specified, then last opened connection which a user used by mysql_connect will be used in the current one.

Example:

Creating a database:

 

  1. <html>
  2. <head>
  3. <title>Creating  your own MySQL Database</title>
  4. </head>
  5. <body>
  6. <?php
  7. $dbhost = 'localhost';
  8. $dbusername = 'root';
  9. $dbpassword = 'rootpassword';
  10. $con = mysql_connect($dbhost, $dbusername, $dbpassword);
  11. if(! $con )
  12. {
  13.   die('Could not connect: ' . mysql_error());
  14. }
  15. echo 'Connected successfully<br />';
  16. $mysql = 'CREATE  YOUR OWN DATABASE TUTORIALS';
  17. $Result = mysql_query( $sql, $con );
  18. if(! $result )
  19. {
  20.   die('Could not create database due to error: ' . mysql_error());
  21. }
  22. echo "Database TUTORIALS created successfully without any error\n";
  23. mysql_close($conn);
  24. ?>
  25. </body>
  26. </html>
Facebook Comments
(Visited 83 times, 1 visits today)
SHARE
Previous articleHotel ERP System Version 3.3
Next articleDrop Database using MySqladmin:
Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!

LEAVE A REPLY

Please enter your comment!
Please enter your name here