当前位置:网站首页>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 market of diesel fire pump 2022-2028: Research Report on technology, participants, trends, market size and share
- Multi sensor fusion of imu/ electronic compass / wheel encoder (Kalman filter)
- Yiwen gets rid of the garbage collector
- Hcip day 12 (BGP black hole, anti ring, configuration)
- The maximum happiness of the party
- Ultrasonic sensor flash | LEGO eV3 Teaching
- Getting started stm32--gpio (running lantern) (nanny level)
- CJ mccullem autograph: to dear Portland
- Registration and skills of hoisting machinery command examination in 2022
- Simple and beautiful method of PPT color matching
猜你喜欢
透彻理解JVM类加载子系统
终于搞懂什么是动态规划的
2022 registration examination for safety management personnel of hazardous chemical business units and simulated reexamination examination for safety management personnel of hazardous chemical busines
Three. Js-01 getting started
Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
如何快速理解复杂业务,系统思考问题?
Element operation and element waiting in Web Automation
Alibaba Tianchi SQL training camp task4 learning notes
Development specification: interface unified return value format [resend]
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
随机推荐
Hainan Nuanshen tea recruits warmhearted people: recruitment of the product experience recommender of Nuanshen multi bubble honey orchid single cluster
Error when LabVIEW opens Ni instance finder
2:第一章:认识JVM规范1:JVM简介;
(4)UART应用设计及仿真验证2 —— TX模块设计(无状态机)
Use the rewrite rule to rewrite all accesses to the a domain name to the B domain name
Multi view 3D reconstruction
openresty ngx_lua正则表达式
(4)UART應用設計及仿真驗證2 —— TX模塊設計(無狀態機)
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Development specification: interface unified return value format [resend]
Element operation and element waiting in Web Automation
Global and Chinese markets for children's amusement facilities 2022-2028: Research Report on technology, participants, trends, market size and share
Registration and skills of hoisting machinery command examination in 2022
Krypton Factor-紫书第七章暴力求解
Sum of two numbers, sum of three numbers (sort + double pointer)
Three. JS VR house viewing
Getting started stm32--gpio (running lantern) (nanny level)
Global and Chinese market of networked refrigerators 2022-2028: Research Report on technology, participants, trends, market size and share
Shell: operator
Tensor attribute statistics