当前位置:网站首页>MySQL related summary
MySQL related summary
2022-06-13 01:17:00 【A simple heart】
1. Interactive command login mysql The failure is as follows :
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
This situation requires password verification , You can skip password verification by configuring the file ;
The operation steps are as follows :
edit /etc/mysql/my.cnf The configuration file , And add the following options in the configuration file to skip password verification .
It's restarting mysql Effective ,/etc/init.d/mysql restart .
2, Change database password
Above 1 in , By skipping password verification , Log in directly to mysql in . Here's the picture :
Use the command to change the password , The following command shows :
As shown in the figure above , You may need to select a specific database after logging in , Because there may be multiple databases . According to use use Database name , Set a password for a specific database .
Select and then set the specific password , Here's the picture :
notes ( The following error occurs when setting the password :
stay mysql5.7 after , Because the field is removed , Use authentication_string Fields instead of password that will do .
update user set authentication_string=password(“123456”) where user=“root”;
Then, perform the following operations .
mysql> flush privileges;
password(‘ New password ’), Remove the previous option to skip password verification , Restart the data . Here's the picture :
Above is mysql How to set the database password .
3.limit Usage Summary
# The formula
# The current page curpage, How much data per page pageNum
#select * from app where 1=1 limit (curpage -1)*pageNum,pageNum;
# Query the data on the second page
select * from app where 1=1 limit 10,10;
# Look up the data on page three
select * from app where 1=1 limit 20,10;
#limit n, The number of rows representing the presentation of the query
select * from app where 1=1 limit 10;
# Total number of records
select count(*) from market_app where 1=1;
# Total number of pages
# totalpage Total number of pages ,totalNum- General record ,pageNum - Records per page
int totalpage = (totalNum + pageNum - 1)/pageNum
# Used for front-end page statistics paging
Optimize : When there is a limit m,n When ,m When I was very old , The query process will scan m frequency , Will affect performance , An optimization method , Add corresponding condition , To optimize , Reduce scanning m Value , In addition, according to id Condition optimization , Reduce the number of queries , So as to optimize query efficiency .
summary :
1.limit It can only be followed by pure numbers .
2.limit Followed by offset,count Must be greater than 0, also offset The default can be 0.
3,limit The following expression is not allowed .
4, In paging query , Sorting cannot be ambiguous , Otherwise, it will be out of order , You can add other fields in the condition as condition judgment .
4. View
The difference between views and tables , The view is to encapsulate the data to be queried , It's like a temporary table , Isolate from the original table , If you often need these data , You can create views to facilitate queries . In addition, views simplify a large number of complex sql Implementation process , So that visitors cannot access the original data table , Ensure the security of data .
(1) The view is compiled SQL sentence , Is based on SQL Visual table of result set of statement , The watch is not .
(2) The view has no physical record , And the basic tables are .
(3) The table is the content , The view is the window .
(4) Tables occupy physical space while views do not , Views are just logical concepts , The watch can check it in time Make changes , But the view can only be modified with the created statement .
(5) A view is a way to view a data table , You can query the data formed by some fields in the data table , Just some SQL Collection of statements . In terms of security , Views prevent users from touching data tables , So the user doesn't know the table structure .
(6) Tables belong to tables in global mode , It's real ; The view belongs to the local schema table , It's a virtual watch .
(7) View creation and deletion only affect the view itself , Does not affect the corresponding basic table .
The connection between the two :
View (view) It's a table built on top of the basic table , Its structure ( The defined column ) And content ( That is, all records ) All from the basic watch , It exists according to the basic table . A view can correspond to a basic table , also
It can correspond to multiple basic surface . Views are abstractions of basic tables and new relationships in a logical sense
5. perform sql When the sentence is , Report errors 1055 error message , This is because in the mysql5.7 Then set the limit . stay sql_mode The default is ONLY_FULL_GROUP_BY,SQL Statement failed ONLY_FULL_GROUP_BY Semantic check so error report .
ONLY_FULL_GROUP_BY:ONLY_FULL_GROUP_BY requirement select The columns queried in the statement must be explicit ( The same is true of other statements ).
With SQL sentence select columes from table group by list For example :columns Must be an aggregate function or in group by The expression after list in , also list The must contain a primary key , Otherwise, it will also report an error .
insert、update、delete Statements will report errors ( But it doesn't affect SQL Execution of statements ), Because the query operation will also be performed before the execution of these three statements .
Take the primary key as id For example :
SELECT count(1) FROM customer GROUP BY name; The SQL Successful implementation , because count Is an aggregate function ;
SELECT * FROM customer GROUP BY name; The SQL Execution failure , because * Contains the primary key id, and group by The expression after does not contain id
SELECT name FROM customer GROUP BY name; The SQL Successful implementation , because name Included in group by In the following expression
SELECT name, contact FROM customer GROUP BY name; The SQL Execution failure , because contact Not included in group by The solution of the following expression is as follows :
a. Add... To the fields to be queried any_value() Enclose the function , Can solve .
b.win with hands MySql Medium my.ini Medium sql_mode Configuration items can be modified , hold only_full_group_by Item Deletion , If it is Linux It's in my.cnf in .
3… If there is no sql_mode term , adopt sql Statement modification
select @@sql_mode
Remove the found value only_full_group_by term , Add other items to my.ini In profile
sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.
边栏推荐
- 5G工业网关在煤矿行业的应用优势
- Work and life
- [Latex] 插入图片
- np.concatenate中axis的理解
- Facial expression recognition dataset
- 【斯坦福計網CS144項目】Lab1: StreamReassembler
- Common skills for quantitative investment - drawing 3: drawing the golden section line
- Jenkins持续集成操作
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators
- [backtrader source code analysis 7] analysis of the functions for calculating mean value, variance and standard deviation in mathsupport in backtrader (with low gold content)
猜你喜欢

Minimum spanning tree problem

spiral matrix visit Search a 2D Matrix
![[003] embedded learning: creating project templates - using stm32cubemx](/img/18/43dfa98f1711e8e544828453e36812.jpg)
[003] embedded learning: creating project templates - using stm32cubemx

Et5.0 configuring Excel

Et5.0 value type generation

Leetcode question brushing 06 bit operation

Leetcode find duplicates

使用Pygame创建一个简单游戏界面

Common skills for quantitative investment - drawing 2: drawing the moving average

Leetcode 01 array
随机推荐
Alexnet implements image classification of caltech101 dataset (pytorch Implementation)
生态聚合NFT来袭,Metaverse Ape引领Web 3.0元宇宙新范式革命
3623. Merge two ordered arrays
Binary tree traversal - recursive and iterative templates
Five classic articles worth reading (2)
Study notes on the introduction paper of face recognition deep facial expression recognition: a survey
Leetcode question brushing 06 bit operation
Method of cleaning C disk
Common skills for quantitative investment - indicators Chapter 3: detailed explanation of RSI indicators, their code implementation and drawing
Argparse command line passes list type parameter
Et5.0 value type generation
Lecture on Compilation Principles
pycharm add configutions
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators
Addition and modification of JPA
Characteristics of transactions - persistence (implementation principle)
304. Merge two ordered arrays
Plusieurs catégories de tests logiciels sont claires à première vue
五篇经典好文,值得一看(2)
Leetcode find duplicates