[MySQL] Database -- operation of the library

 

basic concept:

     SQL is a set of operational commands specially built for databases and is a full-featured database language . When using it, you only need to issue a "what to do" command, and "how to do it" does not need to be considered by the user. SQL is powerful, easy to learn, and easy to use. It has become the basis of database operations, and almost all databases now support SQL .

MySQL is a relational database management system, a relational database keeps data in different tables instead of keeping all the data in one big warehouse, which increases speed and improves flexibility. The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software adopts a dual-licensing policy, which is divided into community version and commercial version. Due to its small size, fast speed, low total cost of ownership, and especially open source , MySQL is generally chosen as the website database for the development of small and medium-sized websites.
The following summarizes the basic syntax of the database:
1, mysql shutdown and startup

[root@bogon Desktop]# service mysqld stop #Close 

[root@bogon Desktop]# service mysqld start #Start

 2. The relationship between database server, database and table
1. The so-called installation of database server is just to install a database management program on the machine. This management program can manage multiple
databases . Generally, developers will create a database for each application.
2. In order to save the data of the entities in the application, multiple tables are generally created in the database to save the data of the entities in the program.

The relationship between database server, database and table is as follows:

The basic statement of building a library:

create database 库名;

Use the library:

use library name;

The basic syntax for creating a table:

create table 表名(
Field 1 Column Type 1,
Field 2 Column Type 2,
...
field n column type n
);

Insert data:

insert into tablename(fieldname1, field2, ...) values(values1, value2);

View the data in the table:

select * from 表名;

Operation of the library:

create database

语法: CREATE DATABASE [IF NOT EXISTS] db_name [create_specification [, create_specification] ...

create_specification:
[DEFAULT] CHARACTER SET charset_name
[DEFAULT] COLLATE collation_name

Notice:

capitalize keywords

[] is optional

CHARACTER SET: Specifies the character set used by the database

COLLATE: Specifies the comparison method of the database character set (default utf8_general_ci, generally not specified)

The command to view the system default character set and validation rules is:

show variables like 'character_set_database';
show variables like 'collation_database';

Character set and validation rules

See which character sets are supported by the database:


Verification rules:
1. Case sensitive

Create a database, the validation rules use utf8_general_ci [case insensitive]


Create a database, the validation rules use utf8_general_bin [case sensitive]


2. Affect sorting

mysql> use ccc;
mysql> select * from person order by name;
+------+
| name |
+------+
| A |
| B |
| a |
| b |
+------+
mysql> use bbb;
mysql> select * from person order by name;
+------+
| name |
+------+
| a |
| A |
| b |
| B |
+------+
Manipulate the database
1. View the database

show databases; Example:


2. Display the database creation statement

show create database database name; 


Notice:

1) MySQL 建议我们关键字使用大写,但是不是必须的。
2) 数据库名字的反引号``,是为了防止使用的数据库名刚好是关键字

3) /*!40100 default.... */ 这个不是注释,表示当前mysql 版本大于4.01版本,就执行这句话。

3. 数据库删除

DROP DATABASE [IF EXISTS] db_ name;


4. 查看当前MySQL数据库的连接情况 show processlist;

5. 备份和恢复数据库:基本语法: [root@localhost Desktop]# mysqldump -u root -p密码 数据库名 > 数据库存放路径

修改库

语法: ALTER DATABASE [IF EXISTS] db_name [alter_spacification [,alter_spacification]...]

alter_spacification:
[DEFAULT] CHARACTER SET charset_name
[DEFAULT] COLLATE collation_name

 删除库

drop database 数据库名字;
当执行这句话后:
1. 数据库内部看不到对应的数据库
2. 对应的数据库文件夹被删除,级联删除,里面的数据表全部被删

注意:不要随意删除数据库。

    以上便是数据库中库的基本操作,库的基本操作是学习数据库的基础。MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。关于数据库的其它操作将在后期为大家总结,有不足的地方欢迎大家批评指正 !

Guess you like

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