Database operat...LOGIN

Database operations

6.1 Database operation

Create database

QQ截图20161009141112.png


##Example:


mysql> create database php;
 Query OK, 1 row affected (0.00 sec)

"Query OK" means that the above command is executed successfully. "Query OK" is displayed after all DDL and DML (excluding SELECT) operations are executed successfully. It is understood that the execution is successful; "1 row affected" means that the operation only affects records a row in the database, and "0.00 sec" records the execution time of the operation.

If this database already exists, the system will display:

mysql> create database liwenkai;
 ERROR 1007 (HY000): Can't create database 'liwenkai'; database exists

View database

QQ截图20161009141144.png## Note:

show refers to display

database refers to the database

databases is the plural form of database, referring to all databases.

Example:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| php                |
| test               |
+--------------------+
5 rows in set (0.00 sec)

Select database

##Use database liwenkaiQQ截图20161009141208.png

Note:
use refers to use;

The library name is the name of the specific database that exists in the current database system;


Example:

mysql> use php;
 Database changed

This will enter the php database. Of course, you can use the use statement to switch the database you want to operate at any time. PHP has just been selected. Now let’s switch to the mysql database with mysql content and see:

mysql> use mysql;
 Reading table information for completion of table and column names
 You can turn off this feature to get a quicker startup with -A
 Database changed

The appearance of "Database changed" indicates that the switch is successful. Then, see what is in the mysql database (use the show statement the same as viewing the current database server database)

View the tables in the database

After entering the library, we can see what is in the library How many data tables.


QQ截图20161009141231.png

Use use to enter a database and use show tables

Example, view the tables of the current database:

mysql> show tables;
 +---------------------------+
 | Tables_in_mysql |
 +---------------------------+
 | columns_priv |
 | db |
 | event |
 | func |
 | general_log |
 | help_category |
 | help_keyword |
 | help_relation |
 | help_topic |
 | innodb_index_stats |
 | innodb_table_stats |
 | ndb_binlog_index |
 | plugin |
 | proc |
 | procs_priv |
 | proxies_priv |
 | servers |
 | slave_master_info |
 | slave_relay_log_info |
 | slave_worker_info |
 | slow_log |
 | tables_priv |
 | time_zone |
 | time_zone_leap_second |
 | time_zone_name |
 | time_zone_transition |
 | time_zone_transition_type |
 | user |
 +---------------------------+
 28 rows in set (0.00 sec)

The content in these tables is information data related to users, permissions, database status, settings, etc. related to the relational database server.



Example description

Delete a database, the name of the database is php

QQ截图20161009141248.png

Note:
drop is Chinese and can be translated as falling down, no more.

database refers to the database

The library name refers to the name of the library to be deleted

Example:

mysql> drop database liwenkai;
 Query OK, 0 rows affected (0.01 sec)

[Remember] Note: After the database is deleted, all the data below will be deleted, so before deleting Be careful and make appropriate backups.

Next Section
<?php echo "Hello Mysql"; ?>
submitReset Code
ChapterCourseware