Database_6_SQL basic operations - library operations

SQL basic operations - library operations: additions, deletions, changes, and queries to the database

1. Add a new database (create)

Basic syntax: Create database database name [library options];

The library option is used to constrain the database, which is divided into two options: 1. Character set setting: charset/character Specific character set (encoding format of data storage) Common character set: GBK and UTF8 (UTF8 cannot add a dash or underscore)

                  2. Proof set setting: collate specific proof set (rules for data comparison)

Create a file with the extension sql, such as sql_2018_0503.sql (copy its content into the Mysql command window)

-- sql_2018_0503.sql content:

-- Double dash + space: comment (single-line comment), you can also use the # sign (only at the beginning, not in the sentence)

# create database
create database mydatabase charset utf8;-- create a database named mydatabase

Note: ## can only be used as a comment at the beginning, not in the sentence

Among them: the database name cannot use keywords (characters that have been used) or reserved words (may be used in the future)

# create keyword database (error)
create database database charset utf8;-- create a database named database

If you must use keywords or reserved words, the name must use two backticks (the output of the key below the esc key in English: `)

# use backticks
create database `database` charset utf8;

It is possible to use a Chinese database, but there are prerequisites: ensure that the server can recognize it (not recommended)

-- Create a Chinese database (it is wrong to create it directly, no matter if it is not as good as backticks, it does not need backticks itself
create database 中国 charset utf8;
create database `中国` charset utf8;

-- Solution: Tell the server what the current Chinese character set is (View method: upper left corner of the command window -> Properties -> Options)
set names gbk;
create database Chinese charset utf8;-- no need to add backticks

What happens after the SQL statement that creates the database is executed?

  1. .In the database system, the corresponding database information has been added
  2. It will be under the folder where the data is saved: the Data directory, and create a folder corresponding to the database name

 

  3. There is an opt file under each database: database options are saved

Note: The collation set depends on the character set refers to: the character set changes the collation set will also change

2. Check the database

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325340338&siteId=291194637