Mysql database ...LOGIN

Mysql database operation

Create database

##ExampleExample descriptionCreate a database, the name of the database is PHP
CategoryDetailed explanation
Basic syntaxCREATE DATABASE database name;
CREATE DATABASE PHP;
Example:

mysql> CREATE DATABASE PHP;

Query OK, 1 row affected (0.00 sec)

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

If this database already exists, the system will display:

mysql> CREATE DATABASE PHP;

ERROR 1007 (HY000): Can't create database 'PHP'; database exists

View database

Basic syntax:

CategoryDetailed explanationBasic syntaxExample descriptionDisplay all databases of the current server
show databases;
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 |
| user             |
+--------------------+
4 rows in set (0.00 sec)

Selected database

Basic syntax:

##CategoryBasic syntaxuse library name;# #ExampleExample descriptionUse database PHP
Detailed explanation
use PHP
# #

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 to be operated at any time. PHP has just been selected. Now let’s switch to the mysql database with mysql content and take a look:

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

If "Database changed" appears, 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.

CategoryDetailed explanation
Basic syntaxshow tables;
Example descriptionShow all tables under the current database

After using use to enter a database, you can use show tables

Example to 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.

Delete database

CategoryDetailed explanation
Basic syntax DROP DATABASE library name;
ExampleDROP DATABASE PHP;
Example descriptionDelete a database, the name of the database is liwenkai

Note:
drop is in Chinese Translated to mean falling down, no longer needed
database refers to the library
The library name refers to the name of the library to be deleted

Example:

mysql> DROP DATABASE PHP;
Query OK, 0 rows affected (0.01 sec)

【Remember】Note: After the database is deleted, all data below will be deleted, so be careful and make appropriate backups before deleting. (If important data is not backed up, the actual data risk has nothing to do with this book.)

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