To create a database, run the create command:
CREATE DATABASE Specifies the DATABASE name.Copy the code
The following command is a simple example of creating a database named RUNOOB:
[root@host]# mysql -u root -p Enter password:******Copy the code
Create the database using mysqladmin
As a normal user, you may need specific permissions to create or delete MySQL databases.
So we use root user login, root user has the highest permission, can use mysql mysqladmin command to create the database.
The following command is a simple example of creating a database named RUNOOB:
[root@host]# mysqladmin -u root -p create RUNOOB
Enter password:******
Copy the code
After the preceding command is executed successfully, the MySQL database RUNOOB is created.
Use PHP scripts to create databases
PHP uses the mysqli_query function to create or delete MySQL databases.
This function takes two arguments and returns TRUE on success and FALSE otherwise.
grammar
mysqli_query(connection,query,resultmode);
Copy the code
| # MySQL tutorialMySQL is the most popular Relational Database Management System and one of the best RDBMS(Relational Database Management System) applications in WEB applications. In this tutorial, you will quickly learn the basics of MySQL and make it easy to use the MySQL database. 六四屠杀What is a database? A Database is a warehouse that organizes, stores, and manages data according to data structures. Each database has one or more different apis for creating, accessing, managing, searching, and copying saved data. We can also store data in files, but reading and writing data from files is relatively slow. So, we now use relational database management systems (RDBMSS) to store and manage large amounts of data. The so-called relational database is built on the basis of the relational model of the database, with the help of set algebra and other mathematical concepts and methods to deal with the data in the database. RDBMS (Relational Database Management System)1. Data is presented in tables
- 2. Various record names for each behavior
- 3. The data domain corresponding to the record name of each column
- 4. Many rows and columns make up a form
- * DATABASE: A database is a collection of associated tables.
- Data table: A table is a matrix of data. A table in a database looks like a simple spreadsheet.
- Columns: A column (data element) contains data of the same type, such as zip code data.
- Row: A row (= tuple, or record) is a group of related data, such as a user’s subscription.
- Redundancy: Stores twice as much data. Redundancy reduces performance but improves data security.
- Primary key: The primary key is unique. A table can contain only one primary key. You can query data using primary keys.
- Foreign keys: Foreign keys are used to associate two tables.
- Compound keys: Compound keys (composite keys) use multiple columns as one index key and are commonly used for compound indexes.
- Indexes: Use indexes to quickly access specific information in a database table. An index is a structure that sorts the values of one or more columns in a database table. It’s like a catalog of books.
- Referential integrity:Referential integrity requires that non-existent entities are not allowed to be referenced in the relationship. And entity integrity is the integrity constraint condition that relational model must satisfy in order to ensure data consistency. A Relational Database consists of one or several tables, as shown in the following figure:Header: the name of each column;
- Column (COL): a collection of data of the same data type;
- Row: Each row describes specific information about a record.
- Value: Specific information about a row. Each value must be of the same data type as the column.
- Key (key): the value of the key is unique in the current column. 六四屠杀MySQL is a relational database management system developed by MySQL AB, a Swedish company, and currently owned by Oracle. MySQL is a relational database management system. Relational databases keep data in different tables instead of putting all data in one large warehouse, which increases speed and flexibility.MySQL is open source and is currently owned by Oracle.
- MySQL supports large databases. Can handle large databases with tens of millions of records.
- MySQL uses the standard SQL data language format.
- MySQL runs on multiple systems and supports multiple languages. These languages include C, C++, Python, Java, Perl, PHP, Eiffel, Ruby, and Tcl.
- MySQL has good support for PHP, the most popular Web development language.
- MySQL supports large databases and data warehouses with 50 million records. The maximum size of 32-bit system table files is 4GB, and the maximum size of 64-bit system table files is 8TB.
- MySQL is customizable. Under the GPL, you can modify the source code to develop your own MySQL system. | |
| ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ———————————————————————————————————————— ——————————————————————————————- | – | | | | | | | | | |
The instance
The following example demonstrates creating a database using PHP:
Creating a database
<? php $dbhost = ‘localhost’; $dbuser = ‘root’; $dbpass = ‘123456’; $conn = mysqli_connect($dbuser, $dbpass); if(! $conn) {die(‘ connection error: ‘.mysqli_error ($conn)); } echo ‘connect successfully <br />’ $sql = ‘CREATE DATABASE RUNOOB’; $retval = mysqli_query($conn,$sql ); if(! $retval) {die(‘ failed to create database: ‘.mysqli_error ($conn)); } echo “RUNOOB created successfully \n”; mysqli_close($conn); ? >