当前位置:网站首页>Mysql database related operations
Mysql database related operations
2022-07-27 03:26:00 【Caribbean waves】
Related operations for database
Hello everyone , This time I bring you my new column : database , The database is relatively not that difficult , As long as you practice hard 、 Memorize grammar , I believe that learning database well is not a problem , Bloggers will start from 0 analyse , Explain the knowledge points of database step by step , And will give many examples . most important of all , Bloggers will not use software , Use the most primitive way -> Command line to explain , The advantage of this explanation is to write sentence by sentence , It won't cause the problem that readers can't keep up with their ideas !
QQ:162196770
WeChat :PRIDE_Xu_
Gitee:https://gitee.com/jialebihaitao
Previous blog portal :
The next blog portal :
Article column :
B standing : Under construction , I will consider in the future B Explain some knowledge points on the station and so on
1、 Operation of database
1.1 Displays the current database
Displays which databases exist on the current server ( Or what data sets )
grammar :
show databases;

Be careful :
databasesIt's the pluralshowanddatabasesSpace between ( A few don't matter , But not without !)SQLStatements are basically based on;At the end of theSQLStatement is case insensitive- The default built-in database , Don't move about ! It's not fun to break the database ~
1.2 Create database
grammar :
create database [if not exists] Database name [ Create rules ];

Be careful :
All the rest
[]There is no need to input , This[]Represents optional ( Write but not write );As long as the name of the database is not the name of the keyword ( In fact, you can also create databases with keywords as their names , Use inverted quotation marks , namely
Just wrap this symbol ( Position inTab upper ,1 To the left of ,Esc Below )), But be careful : Not on a server Create multiple databases with the same name
if not existsThe function of is to create as long as it doesn't exist , In fact, it can beUse scenarios : You send someone a paragraph
SQL, But you don't know whether there is a corresponding database on his computer , So choose if not to create this way . Others have already created , Let's not fool aroundInside
databaseIt's singularCreate rules : When creating a database, you can specify character sets and verification rules
Validation rules : Describes the comparison method between current characters
Compare the equality of strings / Size relationship ( For example, we sometimes want to ignore case )
There are not many scenarios , We seldom intervene manually , Generally, you can use the default verification rules .
Character set :
create database test character set utf8mb4;
Inside
utf8mb4What's going on ?First , Let's think about it first , How does a computer save letters ?
ASCII code : By numbers , To represent letters . The one-to-one correspondence between numbers and letters , become ASCII clock
however ASCII It does not contain Chinese , So now two versions are commonly used
GBK2 Bytes to represent a Chinese character
yes
WindowsThe default character encoding of simplified Chinese versionUTF-8: Be regarded as " Universal character encoding "UTF8Variable length coding : A Chinese character , In a few bytes , It's uncertain .It's usually 3 A byte means a Chinese character
Essentially , Is to use numbers to represent symbols in various languages , Corresponding large table , This mapping relationship is called " Character set "
So the one above
utf8mb4What's going on ?utf8mb4Actually, it's better thanutf8There are some special symbols , such asemojiexpression . Set toutf8NothingSo we learned such a thing before
char* s = " hi "; printf("%d\n",strlen(s)); // So, please. , How many bytes does a Chinese character occupy // Through the right GBK as well as UTF8 Explanation , We can see : // You need to confirm which character code it is // GBK -> 2 Bytes // UTF8 -> 3 Bytes 1
Implement this
SQLTime spent in operation : We can see the picture just now , The running time is0.03sec, This is relative to computers , It's actually a very slow speedLet me introduce you the following time of common computer operations :
Access the network :s~ms
Access disk :ms~us
Access memory :us~ns
operation CPU:ps
Be careful : This conversion is 1000, No 1024. Don't get mixed up
Databases are often slow links , Large projects are prone to problems .
1.3 Using a database
Before performing a series of operations on the database , We must select the database first
grammar :
use Database name ;

Use the database statement , No addition ; Can also carry out . But it's not recommended , stay SQL in , Some sentences can be omitted ;, But some statements must be added ;, So we add ;, Let you see which SQL The statement did not add ; Don't be surprised

1.4 Delete database
This operation is dangerous !!! Never delete the database on the company's server .
grammar :
drop database Database name ;

In fact, it can be retrieved , But it's troublesome .
Can be opened
MySQLOfbinlogfunction , Every operation on the database , Will be recorded asbinlogin . ten thousand ⼀ Data destroyed , You can rebinlogImport all operations in ⼀ All over , But the content is not complete

So is there a way , Avoid deleting data in the production environment ?
Access control : Provide administrator privileges , Only administrators can delete
Produced a profession :
DBADatabase administratorBack up a copy : Once deleted , There is still a way to go
Is it possible that permission control has also failed , The backups have also been deleted ? It's certainly possible , That is not “ False deletion ” 了 , It was intentional , Will be sent to a good place to eat and live .
Recover hard disk data :
1.5 Expand :cmd Minor operations
- Press and hold the up and down keys on the keyboard to find historical commands ( Save your energy )
- Copy and paste : Select content , Press enter to copy , Right click Paste
1.6 The environment involved in the company ( Digression )
Office environment : On entry , The computer sent to you by the company ( Of course, there are also a few companies , I will let you bring your computer -> Basically run fast , Far away ), Will use this computer for daily office . The basic configuration is
8 nucleus CPU 16G Memory 512G Hard diskdevelopment environment : It is generally provided in the form of server , The office computer is connected to the server through the network . The corresponding device of this server is generally about
16 nucleus CPU 64G Memory 4T Hard diskSome projects are very resource consuming , A bad start-up memory will eat dozens G, Or even hundreds G. Of course, you can't use your own office computer .
If the developed program is relatively small , At this time, there may be no development environment , You can directly use the office computer to develop .
Generally, the company brings the equipment that has passed the warranty period to the programmer as " development environment "
Test environment : The environment used by the testing staff for the program to be tested , The machines used are basically those that have passed the warranty period
The online environment / Production environment : It is also provided in the form of server , You also need to connect remotely through the network of your office computer . Good configuration , about
56 nucleus CPU 256G/512G Memory A number of T Hard diskProduction environment , In fact, it is an environment that provides services to external users , Never hang up !
Hanging up will cause major resource losses
that MySQL The server will basically appear on the top 2 3 4 Environment , If it is deleted by mistake 2 3 Database in the environment , In fact, the situation is relatively good , The colleagues worked overtime and were rescued , Basically, it will be scolded by many people . But once you accidentally delete 4 That is, the database in the online environment , Then it's over . Users outside will feel the direct impact , The probability will lead to the loss of users , Take legal action and so on . Serious will cause major safety accidents !
边栏推荐
- Abbkine AbFluor 488 细胞凋亡检测试剂盒特点及实验建议
- 客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实
- [common search questions] 111
- spark:计算不同分区中相同key的平均值(入门级-简单实现)
- mysql底层数据结构
- MySQL:互联网公司常用分库分表方案汇总
- opiodr aborting process unknown ospid (21745) as a result of ORA-609
- OC-消息机制
- Post responsibilities of safety officer and environmental protection officer
- Leetcode 207. curriculum (July 26, 2022)
猜你喜欢

数据库概论 - 数据库的介绍

Message rejected MQ

30 minutes to thoroughly understand the synchronized lock upgrade process

vector 转 svg 方法

Customer cases | pay attention to the elderly user experience, and the transformation of bank app to adapt to aging should avoid falsehood and be practical

LPCI-252通用型PCI接口CAN卡的功能和应用介绍

Explain

【1206. 设计跳表】

flask_restful中reqparse解析器继承

Take you to know what Web3.0 is
随机推荐
阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题
MySQL:互联网公司常用分库分表方案汇总
FactoryBean的getObject调用时机
Sqlserver select * can you exclude a field
一种分布式深度学习编程新范式:Global Tensor
快速排序及优化
Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
Idea 中添加支持@Data 插件
深入理解Mysql索引底层数据结构与算法
MySQL中文失败问题
Explain工具实际操作
积分发放带给商家的两个帮助
Graphic SQL, this is too vivid!
Method of converting curtain article OPML into markdown
Pytoch loss function summary
Database usage security policy
围圈报数(北理工机试题)(DAY 83)
Detailed explanation of const usage in C language
How to design the red table of database to optimize the performance
175. Combine two tables (very simple)
