当前位置:网站首页>MySQL (1) -- related concepts, SQL classification, and simple operations
MySQL (1) -- related concepts, SQL classification, and simple operations
2022-07-05 23:13:00 【Dutkig】
One 、 database ? Database management system ?SQL? What is the relationship ?
database : English words DataBase, abbreviation DB. A combination of files that store data in a certain format .
seeing the name of a thing one thinks of its function : A warehouse for storing data , It's actually a bunch of files . These files store Data with a specific format .Database management system : DataBaseManagement, abbreviation DBMS.
Database management system is specially used to manage the data in the database , Database management system can Add, delete, modify and query the data in the database .Common database management system : MySQL、Oracle、MS SqlServer、DB2、sybase etc. …
SQL: Structured query language Programmers need to learn SQL sentence , Programmers write SQL sentence , then DBMS Responsible for the execution of SQL sentence , Finally to complete the database of data addition, deletion, modification and query operation .
SQL It's a set of standards , What programmers mainly learn is SQL sentence , This SQL stay mysql Can be used in , At the same time Oracle Can also be used in , stay DB2 Can also be used in .
The relationship between the three
DBMS– perform –> SQL -- operation –> DB
SQL The classification of sentences
SQL There are many sentences , It's best to classify , It's easier to remember , It is divided into :
DQL: Data query language ( Usually with select Keywords are all query statements )select…
DML: Data operation language ( All additions, deletions and modifications to the data in the table are DML)insert delete update( This is mainly the data in the operation table data).
DDL: Data definition language ( Usually with create、drop Delete 、alter All the changes are DDL). The main operation is the table structure . Not the data in the table .
—— This addition, deletion, modification and DML Different , This is mainly used to operate the table structure .TCL: Transaction control language , Include : Transaction submission :commit and Transaction rollback :rollback;
DCL: Data control language . for example : to grant authorization grant、 Revoke authority revoke…
Two 、 Look at the services on the computer , Look for it MySQL Where is your service ?
Computer --> Right click --> management --> Services and Applications --> service --> look for mysql service
MySQL Service for , The default is “ start-up ” The state of , It's only activated mysql Ability to use .
By default “ Automatically ” start-up , Auto start means the next time you restart the operating system
Automatically start the service .
You can right-click on the service :
start-up
Restart the service
Out of Service
...
You can also change the default configuration of the service :
Right click on the service , attribute , Then you can choose the startup mode :
Automatically ( Delayed start )
Automatically
Manual
Ban
3、 ... and 、windows Startup and shutdown in the operating system mysql Service? ?
grammar :
net stop The service name ;
net start The service name ;
The above commands can be used to start and stop other services .
Four 、mysql Installed , Service started , How to use client login mysql Database ?
Use bin In the catalog mysql.exe Command to connect mysql database server
Log in locally ( Show the form of writing a password ):
C:\Users\Administrator>mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Log in locally ( In the form of hidden passwords ):
C:\Users\Administrator>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
5、 ... and 、mysql Common commands
sign out mysql :
exit
see mysql Which databases are in ?
Be careful
: It ends with a semicolon .
show databases;
mysql By default, it comes with 4 A database .
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
- Choose to use a database
use databases;
mysql> use sys;
Database changed
Indicates that you are using a name called sys The database of .
- Create database
create database name;
mysql> create database mk;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mk |
| mysql |
| performance_schema |
| sys |
+--------------------+
- Check which tables are under a database ?
show tables;
mysql> show tables;
Be careful : The above commands are not case sensitive , Will do .
- see mysql Version number of the database :
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.11 |
+-----------+
1 row in set (0.00 sec)
- Check which database you are currently using ?
mysql> select database();
+-------------+
| database() |
+-------------+
| mk |
+-------------+
6、 ... and 、 The most basic unit in the database is the table :table
What is a watch table? Why use tables to store data ?
full name Gender Age ( Column : Field )
---------------------------
Zhang San male 20 -------> That's ok ( Record )
Li Si Woman 21 -------> That's ok ( Record )
Wang Wu male 22 -------> That's ok ( Record )
The data in the database is represented in the form of tables . Because the table is more intuitive .
Any table has rows and columns :
That's ok (row): It's called data / Record .
Column (column): It's called a field . such as : Name field 、 Gender field 、 Age field .
Get to know :
Every field has : Field name 、 data type 、 Constraints, etc .
The field name is understandable , It's an ordinary name , Just see the name and know the meaning .
data type : character string , Numbers , Date, etc.
constraint : There are also many constraints , One of them is called uniqueness constraint ,
7、 ... and 、 Complete some simple operations
Prepare one in advance test.sql Database table of . How to integrate sql What about the data import in the file ?
mysql> source C:\Desktop\test.sql ` Be careful `: No Chinese in the path !!!!
Query OK, 0 rows affected, 1 warning (0.01 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.10 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 1 row affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+-----------------------+
| Tables_in_test |
+-----------------------+
| dept |
| emp |
| salgrade |
+-----------------------+
notes :
- dept It's a department table
- emp It's the staff watch
- salgrade It's the salary scale
View data in table
select * from Table name ;
mysql> select * from emp; // from emp Table queries all data .
+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
mysql> select * from dept;
+--------+------------+----------+
| DEPTNO | DNAME | LOC |
+--------+------------+----------+
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
mysql> select * from salgrade;
+-------+-------+-------+
| GRADE | LOSAL | HISAL |
+-------+-------+-------+
| 1 | 700 | 1200 |
| 2 | 1201 | 1400 |
| 3 | 1401 | 2000 |
| 4 | 2001 | 3000 |
| 5 | 3001 | 9999 |
+-------+-------+-------+
Don't look at the data in the table , Just look at the structure of the table
desc Table name ;//describe
mysql> desc dept;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| DEPTNO | int(2) | NO | PRI | NULL | | Department number
| DNAME | varchar(14) | YES | | NULL | | Department name
| LOC | varchar(13) | YES | | NULL | | Location
+--------+-------------+------+-----+---------+-------+
mysql> desc emp;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| EMPNO | int(4) | NO | PRI | NULL | | Employee number
| ENAME | varchar(10) | YES | | NULL | | Employee name
| JOB | varchar(9) | YES | | NULL | | jobs
| MGR | int(4) | YES | | NULL | | Superior number
| HIREDATE | date | YES | | NULL | | Date of entry
| SAL | double(7,2) | YES | | NULL | | Wages
| COMM | double(7,2) | YES | | NULL | | subsidy
| DEPTNO | int(2) | YES | | NULL | | Department number
+----------+-------------+------+-----+---------+-------+
mysql> desc salgrade;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| GRADE | int(11) | YES | | NULL | | Pay scale
| LOSAL | int(11) | YES | | NULL | | minimum wage
| HISAL | int(11) | YES | | NULL | | Maximum wage
+-------+---------+------+-----+---------+-------+
mysql> describe dept;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| DEPTNO | int(2) | NO | PRI | NULL | |
| DNAME | varchar(14) | YES | | NULL | |
| LOC | varchar(13) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
Next blog , We will enter SQL Sentence learning .
边栏推荐
- Global and Chinese markets for welding products 2022-2028: Research Report on technology, participants, trends, market size and share
- What is the process of building a website
- 视频标准二三事
- Getting started stm32--gpio (running lantern) (nanny level)
- 基于脉冲神经网络的物体检测
- CJ mccullem autograph: to dear Portland
- 2: Chapter 1: understanding JVM specification 1: introduction to JVM;
- Global and Chinese market of diesel fire pump 2022-2028: Research Report on technology, participants, trends, market size and share
- Practice of concurrent search
- Element positioning of Web Automation
猜你喜欢
Go language implementation principle -- map implementation principle
14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
并查集实践
Three. Js-01 getting started
Element operation and element waiting in Web Automation
Tensor attribute statistics
LabVIEW打开PNG 图像正常而 Photoshop打开得到全黑的图像
【原创】程序员团队管理的核心是什么?
Use of grpc interceptor
终于搞懂什么是动态规划的
随机推荐
Thoroughly understand JVM class loading subsystem
Three. Js-01 getting started
数学公式截图识别神器Mathpix无限使用教程
Matlab smooth curve connection scatter diagram
Commonly used probability distributions: Bernoulli distribution, binomial distribution, polynomial distribution, Gaussian distribution, exponential distribution, Laplace distribution and Dirac delta d
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
[screen recording] how to record in the OBS area
Element positioning of Web Automation
From the perspective of quantitative genetics, why do you get the bride price when you get married
Alibaba Tianchi SQL training camp task4 learning notes
Calculating the number of daffodils in C language
Common model making instructions
Leetcode sword finger offer brush questions - day 21
Douban scoring applet Part-2
2: Chapter 1: understanding JVM specification 1: introduction to JVM;
Realize reverse proxy client IP transparent transmission
regular expression
C Primer Plus Chapter 9 question 10 binary conversion
Three. JS VR house viewing
一文搞定class的微觀結構和指令