MySQL Create, delete, and select databases

Source: Internet
Author: User
Tags connect mysql mysql create table name create database
3.3 Creating, deleting, and selecting databases
MySQL provides three database-level statements: Create database for creating databases, drop database to delete databases, use to select the default database.
1. CREATE DATABASE Statement
Creating a database is easy, as long as you give it a name in the CREATE DATABASE statement:

The restriction condition is that the name of the database must be legitimate, that the database must not exist, and that you must have sufficient permissions to create it.
2. DROP DATABASE Statement
Deleting a database is as easy as creating it, and if you have permission, execute the following statement:

Note that you do not use the DROP DATABASE statement indiscriminately, and it will delete the databases and all of its tables. After a database has been deleted, the database will never be. In other words, don't try to execute the statement just to see how it works. If the administrator has completed the database backup properly, the deleted database may still be recoverable.
Note that the database is represented by a directory in the data directory. If some non-table data files are placed in the directory, they are not deleted by the drop DATABASE statement. At this point, the database directory itself is not deleted.
3. Use statement
The USE statement selects a database to be the default (current) database for a given connection to the server:

You must have some sort of access to the database, or you cannot use it. It is not really necessary to select the database in order to use a table in the database, because its tables can be referenced using the Db_name.tbl_name form. However, it is much easier not to specify Database qualifier reference tables. Selecting a default database does not mean that it must be default for the duration of the connection. You can publish any number of use statements to switch between databases arbitrarily, as long as you have permission to do so. Selecting a database also does not restrict you from using only the tables in that database. You can still refer to a table in another database by qualifying the table name with the database name.
When the server's connection terminates, all memory of the server about the default database disappears. That is, if you connect to the server again, it will not remember the database that you selected previously. In fact, assuming that MySQL is multi-threaded, you can handle multiple connections through a single user, and users can connect or disconnect in any order, and the idea that the server will remember the default database is meaningless. In this environment, the phrase "Previously selected databases" is not clear.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.