MySQL learning the fifth day MySQL database basic Operation _mysql

Source: Internet
Author: User
Tags mysql commands mysql view

This article aims at the MySQL database basic operation carries on the study research, needs to understand the friend not to miss this article.

The following are used on the command line under Windows 64-bit operating systems.

Before we learn, let's explain some of the symbolic meanings in the MySQL syntax format:

(1) The brackets ([]) indicate either exist or not, optional parameters. For example: Show{DATABASES | SCHEMAS} [ like

' Pattern ' | WHERE expr]; the contents of [] enclosed in this syntax format can be added.

(2) curly braces ({}) indicate that the command must appear and is a required parameter. For example:CREATE {DATABASE | SCHEMA} [IF not EXISTS]

db_name [DEFAULT] CHARACTER SET [=] charset_name, the data in {} In this syntax format is required.

(3) Vertical bar (|) Represents the selection of both before and after the vertical bar. For example: Ditto.

First, create a database

MySQL creates a database in the following syntax format:

CREATE {DATABASE | SCHEMA} [IF not EXISTS] db_name [DEFAULT] CHARACTER SET [=] charset_name;

Some of these parameters we will slowly learn in the following learning.

Example (here I do not specify the character encoding method):

CREATE DATABASE T1;


Second, view the list of data tables under the current server

How do we list the MySQL database management system database? MySQL View the list of data tables under the current server in the syntax format:

Show {DATABASES | SCHEMAS} [like ' Pattern ' | WHERE expr];

Example:

Show DATABASES;


MySQL successfully installed, the default with four databases, respectively, INFORMATION_SCHEMA, MySQL, Performance_schema and test. The database T1 is the database we just created, which means that the command to create the database is correct. About the MySQL installation case you can refer to a few articles:

MySQL 5.7.12 winx64 Installation configuration method graphics and text tutorial

Ubuntu under MySQL installation and Operation Graphics Tutorial

MySQL5.6 installation diagram (windows7/8_64 bit)

MySQL installation is not how to do MySQL installation failure reasons and solutions

Third, view the warning message

Before looking at the warning message, let's look at an example of creating a database:

 CREATE DATABASE T1;

 CREATE DATABASE IF not EXISTS t1;


adding [if not EXISTS] means that if there is a table with the same name as the table being created, the current table is not created, and if it does not exist, it is created. This is the semantics of if not exists, and not creating a table is not an error, but one of the normal execution results of this statement.

So now we need to look at the warning message and use the syntax format: showwarnings;


Four, view the database information

We did not specify the encoding of the database in the process of creating the database T1, in which we modified the default encoding of the MySQL service, so is the database T1 the default UTF-8 encoding? This requires us to be able to view the basic information of the data.

Show CREATE DATABASE T1;


If we specify the encoding method for GBK in the process of creating the database.

CREATE DATABASE IF not EXISTS T2 CHARACTER SET GBK;

Show CREATE DATABASE T2;


V. Modification of the database

If we want to modify some of these parameters after we successfully create the database, we need to use the syntax format to modify the database:

ALTER {DATABASE | SCHEMA} [Db_name] [DEFAULT] CHARACTER SET [=] charset_name;

Example (modifying the encoding format of the database T2 we just created is the default encoding format UTG8):

 ALTER DATABASE T2 CHARACTER SET UTF8;

Show DATABASE T2;


VI. deleting databases

Since there is an operation to create a database, there must be a syntax format for deleting the database:drop {db | SCHEMA} [IF EXISTS] db_name;

Example: Take a look at the list of databases on the server before deleting it:

Show DATABASES;


We will create the database T2 Delete and view the list of databases again

DROP DATABASE T2;

Show DATABASES;


Vii. access to the database

The syntax format for entering a database in MySQL service is: usedb_name;

Select the MySQL database you want to manipulate, and all MySQL commands will be used only for that database after you use this command.

Example: Usetest;


This operation has been said earlier in our use of MySQL when we verified which database is currently in use when MySQL learns the MySQL prompt in this article under Windows 64-bit system on the fourth day. Next we will use another way to verify which is the current database?

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.