Mysql entry-level series: create, delete, and select databases for MYSQL [group chart] 3.3 create, delete, and select databases
MySQL provides three DATABASE-level statements: create database is used to CREATE a DATABASE, drop database is used to delete a DATABASE, and USE is used to select the default DATABASE.
1. create database statement
It is easy to CREATE a DATABASE. you only need to give its name in the create database statement:
The condition is that the database name must be legal, the database must not exist, and you must have sufficient permissions to create it.
2. drop database statement
Deleting a database is as easy as creating it. if you have the permission, execute the following statements:
Please note that the drop database statement will delete the DATABASE and all its tables. After a database is deleted, the database will never be deleted. In other words, do not try to execute this statement just to see how it works. If the administrator has properly backed up the database, the deleted database may be recovered.
Note that the database is represented by a directory in the data directory. If some non-table data files are stored in this directory, they will not be deleted by the drop database statement. In this case, the Database Directory itself is not deleted.
3. USE statement
USE statement select a database to make it the default (current) database for the given connection of the server:
You must have certain access permissions to the database. Otherwise, you cannot use the database. It is not necessary to select the database to use the table in the database, because it can be referenced in the form of db_name.tbl_name. However, it is much easier to reference a table without specifying a database qualifier. Selecting a default database does not mean that it must be the default database during the connection duration. You can publish any number of USE statements to switch between databases as long as you have the permission to USE them. Selecting a database does not limit you to using only the tables in the database. You can still reference tables in other databases by specifying the table name using the database name.
When the server connection is terminated, all memory of the default database disappears. That is, if you connect to the server again, it will not remember the database you selected previously. In fact, it is meaningless to assume that MySQL is multi-threaded and can process multiple connections by one user so that users can connect or disconnect in any order so that the server can remember the default database. In this environment, the "previously selected database" statement is not clear.