how to create database in mysql?

Discussion in 'PHP' started by elenabush, Oct 9, 2009.

  1. #1
    Hi folks,

    I have XAMPS php software, we wanna run to database Please tell me how to create database in mysql in xamps.
     
    elenabush, Oct 9, 2009 IP
  2. dsignresponder

    dsignresponder Greenhorn

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Depends how can you access the server? You can create MySql database through your browser by pointing it to http://IP_address_of_your_server and then clicking on phpMyadmin
    You can create databases and tables using the command line as well.
    
    mysql> CREATE DATABASE ''databasename'';
    mysql> GRANT ALL PRIVILEGES ON ''databasename''.* TO "''username''"@"''hostname''" IDENTIFIED BY "''password''";
    mysql> FLUSH PRIVILEGES;
    mysql> EXIT
    
    Code (markup):
    Third, you can create databases and tables with PHP files :
    
    <?php
    $con = mysql_connect("localhost","username","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    if (mysql_query("CREATE DATABASE my_db",$con))
      {
      echo "Database created";
      }
    else
      {
      echo "Error creating database: " . mysql_error();
      }
    
    mysql_close($con);
    ?> 
    
    PHP:
    Good luck!
     
    dsignresponder, Oct 9, 2009 IP
  3. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #3
    astrazone, Oct 9, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JAY6390, Oct 10, 2009 IP