About the author: A cloud computing network operation and maintenance personnel, sharing the technology and dry goods of network and operation and maintenance every day.
Motto: Keep your head down and hurry on your way, be respectful
Personal homepage: Homepage of Netdou
Table of contents
1. The client connects to MySQL
1. Relational database (RDBMS)
2). Query the current database
A. Create an itcast database, using the default character set of the database.
B. Create an itheima database and specify the character set
foreword
This series will explain the basics, introduction, operation and maintenance of the MySQL database. This chapter will provide knowledge about the client connection, data model, and SQL of the MySQL database.
1. The client connects to MySQL
2). Method 2: Use the command line tool that comes with the system to execute the command
mysql [-h 127.0.0.1] [-P 3306] -u root -p
参数:
-h : MySQL服务所在的主机IP
-P : MySQL服务端口号, 默认3306
-u : MySQL数据库用户名
-p : MySQL数据库用户名对应的密码
[ ] are optional parameters. If you need to connect to remote MySQL , you need to add these two parameters to specify the remote host IP and port. If
Note: When using this method to connect, you need to configure the PATH environment variable after the installation is complete.
2. Data model
1. Relational database (RDBMS )
- A. Use tables to store data, the format is uniform, and it is easy to maintain.
- B. Use the SQL language to operate, the standard is unified, and it is easy to use.
2. Data model
We can connect to the database management system DBMS through the MySQL client , and then operate the database through the DBMS .
Database Management System (Database Management System) is a large-scale software for manipulating and managing databases, used to establish, use and maintain databases, referred to as DBMS.
You can use SQL statements to operate the database through the database management system, and manipulate the table structure and data in the database.
Multiple databases can be created in one database server, one database can also contain multiple tables, and one table can contain multiple rows of records.
Three.SQL
1. SQL general syntax
- 1). SQL statements can be written in one line or multiple lines, ending with a semicolon.
- 2). SQL statements can use spaces / indentation to enhance the readability of the statement.
- 3). The SQL statement of the MySQL database is not case-sensitive, and it is recommended to use capital letters for keywords.
- 4). Comments:
- Single-line comment: -- comment content or # comment content
- Multi-line comment: /* comment content */
2. SQL classification
point
kind
|
full name
|
illustrate
|
DDL
|
Data Definition
Language
|
Data Definition Language, used to define database objects
(
databases, tables,
field
)
|
DML
|
Data Manipulation
Language
|
Data manipulation language, used to add, delete, and modify data in database tables
|
DQL
|
Data Query Language
|
Data query language, used to query the records of tables in the database
|
DCL
|
Data Control Language
|
Data control language, used to create database users, control database
access permission
|
3. Database operation
1) .Query all databases
show databases ;
2). Query the current database
select database() ;
3). Create a database
create database [ if not exists ] 数据库名 [ default charset 字符集 ] [ collate 排序
规则 ] ;
the case
A. Create an itcast database , using the default character set of the database.
create database itcast;
In the same database server, two databases with the same name cannot be created, otherwise an error will be reported.
This problem can be solved by using the if not exists parameter. If the database does not exist , the database will be created. If it exists, the database will not be created.
create database if not extists itcast;
B. Create an itheima database and specify the character set
create database itheima default charset utf8mb4;
4). Delete the database
drop database [ if exists ] 数据库名 ;
5). Switch database
use 数据库名 ;
use itcast;
Creation is not easy, please pay attention, like, collect, thank you~