[Daily update-mysql Basics] 2. Basic Database Operations

Source: Internet
Author: User

1. Database operations

After entering the database, you should manage the database. The management database is done through SQL.


SQL is a tool used to control and manipulate databases, a language used to communicate with databases. So, the statements we use later are all SQL statements.


First we have to look at what libraries are on this database server.


Show Databses;

Use the commands to see which databases are available.

The query database also supports filtering, such as some databases that do not display it:

Show databases like%shuai%

It matches the library that contains the Shuai characters in the database name.

%: wildcard character that matches one or more characters

_: Wildcard character, which represents a match.

%shuai%: Can match: Woshuai Shuaige Woshuaima

_shuai_: Can match: Wshuaim _SHUAI1

1.1 Default database MySQL

The MySQL library is a database that is created automatically by the database server, which holds various information about the database, such as the user of the database. We used the root account to log in to the database, which is based on the user table information in the MySQL library.

1.2 Creating a Database

The default library in the database we are not going to modify it. To learn the database, we also need to manually create a database,

Create Databse <databaseName>;

Use the CREATE DATABASE command. The database name is recommended to use English letters, numbers, underscores.

When creating a database, you can also specify a character set for the database, using the

Create DATABASE <databaseName> DEFAULT CHARACTER SET UTF8
COLLATE Utf8_general_ci;

The previous setting is the character set, followed by the set Char collation.

1.3 Viewing statements that create a database

Sometimes when we look at a library and want to restore the statement that he created, you can use:

Show CREATE Database <databaseName>;
1.4 Deleting a database

Remember: In MySQL, create a thing may have to write a lot of statements, but Delete, always only a word, all delete a thing in the database is very simple, cautious with delete!

Drop Database <databaseName>;
1.5 Modifying database Information

ALTER DATABASE <databaseName> CHARSET=GBK;
1.6 Judgement

In database operations, we often encounter judgments, such as: If you have this library, we will not create, or if we have this library we delete the library.

If not exists if it does not exist

If exists exists

Note: In the database to be strictly case-sensitive, although the database itself is not so stipulated, but to develop a distinction between small capitalization habits.


[Daily update-mysql Basics] 2. Basic Database Operations

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.