当前位置:网站首页>Creating a database using mysqladmin

Creating a database using mysqladmin

2022-06-24 05:21:00 User 4988376

We can log in MySQL After service , Use create Command create database , The grammar is as follows :

CREATE DATABASE  Database name ;

The following command simply demonstrates the process of creating a database , The data name is RUNOOB:

[[email protected]]# mysql -u root -p   
Enter password:******  #  Enter the terminal after logging in 

mysql> create DATABASE RUNOOB;

Use mysqladmin Create database

Use ordinary users , You may need specific permissions to create or delete MySQL database .

So we use root The user login ,root The user has the highest authority , have access to mysql mysqladmin Command to create a database .

The following command simply demonstrates the process of creating a database , The data name is RUNOOB:

[[email protected]]# mysqladmin -u root -p create RUNOOB
Enter password:******

After the above command is executed successfully, it will create MySQL database RUNOOB.


Use PHP Script Create database

PHP Use mysqli_query Function to create or delete MySQL database .

This function takes two arguments , Returns... On successful execution TRUE, Otherwise return to FALSE.

grammar

mysqli_query(connection,query,resultmode);

Parameters

describe

connection

It's necessary . Stipulate what to use MySQL Connect .

query

It's necessary , Specify the query string .

resultmode

Optional . A constant . It can be any of the following values :MYSQLI_USE_RESULT( If you need to retrieve a lot of data , Please use this )MYSQLI_STORE_RESULT( Default )

  • MYSQLI_USE_RESULT( If you need to retrieve a lot of data , Please use this )
  • MYSQLI_STORE_RESULT( Default )

example

The following example demonstrates the use of PHP To create a database :

Create database

<?php
$dbhost = 'localhost';  // mysql Server host address 
$dbuser = 'root';            // mysql user name 
$dbpass = '123456';          // mysql User name, password 
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die(' Connection error : ' . mysqli_error($conn));
}
echo ' Successful connection <br />';
$sql = 'CREATE DATABASE RUNOOB';
$retval = mysqli_query($conn,$sql );
if(! $retval )
{
    die(' Failed to create database : ' . mysqli_error($conn));
}
echo " database  RUNOOB  Create success \n";
mysqli_close($conn);
?>
原网站

版权声明
本文为[User 4988376]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210817183810566s.html