当前位置:网站首页>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 :
exitsee 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 .
边栏推荐
- 使用rewrite规则实现将所有到a域名的访问rewrite到b域名
- Global and Chinese market of water treatment technology 2022-2028: Research Report on technology, participants, trends, market size and share
- Calculating the number of daffodils in C language
- Global and Chinese markets for reciprocating seal compressors 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022.02.13 - SX10-30. Home raiding II
- Non rigid / flexible point cloud ICP registration
- C Primer Plus Chapter 9 question 9 POW function
- PLC编程基础之数据类型、变量声明、全局变量和I/O映射(CODESYS篇 )
- Multi sensor fusion of imu/ optical mouse / wheel encoder (nonlinear Kalman filter)
- Un article traite de la microstructure et des instructions de la classe
猜你喜欢

数据库基础知识(面试)

Three. JS VR house viewing

Fix the memory structure of JVM in one article
![[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]](/img/03/8fa104b177698a15b7ffa70d4fb524.jpg)
[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]

Initial experience | purchase and activate typora software

Hainan Nuanshen tea recruits warmhearted people: recruitment of the product experience recommender of Nuanshen multi bubble honey orchid single cluster

Using LNMP to build WordPress sites

2022.02.13 - SX10-30. Home raiding II

Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)

基于脉冲神经网络的物体检测
随机推荐
The method and principle of viewing the last modification time of the web page
Global and Chinese markets for reciprocating seal compressors 2022-2028: Research Report on technology, participants, trends, market size and share
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
一文搞定JVM常见工具和优化策略
Calculating the number of daffodils in C language
2022 registration examination for safety management personnel of hazardous chemical business units and simulated reexamination examination for safety management personnel of hazardous chemical busines
Media query: importing resources
视频标准二三事
Déterminer si un arbre binaire est un arbre binaire complet
Multi camera stereo calibration
Global and Chinese markets for children's amusement facilities 2022-2028: Research Report on technology, participants, trends, market size and share
Yiwen gets rid of the garbage collector
Activate function and its gradient
3D reconstruction of point cloud
Roman numeral to integer
[untitled]
The PNG image is normal when LabVIEW is opened, and the full black image is obtained when Photoshop is opened
(4)UART应用设计及仿真验证2 —— RX模块设计(无状态机)
Initial experience | purchase and activate typora software
第十七周作业