当前位置:网站首页>MySQL operation Basics
MySQL operation Basics
2022-06-25 20:59:00 【Zhushuaijie 1】
database : Save and process data
1: species Mysql Sql Server DB2 Oracel
SQL sentence
Open the terminal
yum -y install mysql-server mysql install Mysql
service mysqld start start-up mysql service
mysql -uroot Sign in mysql
database --- Data sheet --- data
Folder hierarchy
Server side
client
data In order to excel In the form of a table
Text data :varchar(100)
Digital data :int
ERROR Error message
Additions and deletions
1:show databases; Check which databases the current server has
2:create database Library name ; Create a database
3:use Library name ; choice / Enter a database
4:show tables; See which tables are in the current library
5:create table Table name ( Name type ); Create a data table
create table abc( full name varchar(100), Age int, Gender varchar(100));
6:select * from Table name ; Query table data
7:desc Table name ; Query table structure
8:insert into Table name values( value 1, value 2); Add data
insert into abc values(' Zhang San ',20,' male ');
insert into Table name ( Name ) values( value ); Specify columns to add data
9:drop database Library name ; Delete table / library
drop table Table name ;
10:delete from Table name ; Delete data
Copy the data :create table Library name . The new name of the table select * from The old name of the table ;
11:update Table name set Name =' value ';
update stu set full name =' Zhang San '; Change data ( Entire column )
update stu set full name =' Zhang San ' where Age =30 or Gender =' male '; Change data ( Specify data )
Conditional expression where Name =' value '
= yes
!= No
> < >= <=
and and
or or
where full name =' Zhang San ' and Gender =' male '
select function
Other functions :
- Aggregate functions
Further processing of the result set : Sum up , Averaging , Statistical quantity , Maximum , minimum value
sum( Name ): Find the sum of all the data in the front row
avg( Field name ): Find the average of all the data in the front row
count( Field name ): Find the quantity of all the data in the front row
max( Field name ): Find the maximum value of all the data in the front row
min( Field name ): Find the minimum value of all the data in the front row
select sum(sal) from emp;
- Null valued function
grammar :
ifnull( Name , hold null Replace with the information to be displayed ): When the field value is null when , Take the value of the second parameter
When the field value is not null when , Use the value of the current field directly
4. How to use the function :
1) Individual test
select Function name ;
select concat(' study hard ',' Day day up ');
2) Nested tests
select The name of the function ( Another function name ());
select length(trim(' hello '));
character string ( written words ):
concat( character string 1, character string 2, character string 3): String splicing
length( character string ): The byte length of the output string ( Spaces also take up a character length )
upper( character string ): Capitalize all strings
lower( character string ): Lowercase all strings
substring( character string , Starting position , Intercept length ): Intercepts a string at a specified location
trim( character string ): Remove the spaces on both sides of the string
ltrim( character string ): Remove the space to the left of the string
rtrim( character string ): Remove the space to the right of the string
replace( character string , Replaced string , String replaced with ): String substitution
strcmp( character string 1, character string 2): Compare the size of two strings ( Compare by text encoding )
chinese > english > Numbers > Symbol
The number :
ceil( decimal ): Rounding up
floor( decimal ): Rounding down
mod( The number 1, The number 2): For the value 1 And numbers 2 Carry out the redundancy operation
select mod(3,2)
rand(): Generate 0-1 Random number between
round( decimal , Keep a few decimal places ): The value is rounded to the specified decimal places
Time :
now(): Get the current time, month, day, hour, minute and second
curdate(): Get the date in the current time
curtime(): Get the hours, minutes and seconds in the current time
year(now()): Get the current year
month( Specify time ): Get the current month
day( Specify time ): Get current day
hour( Specify time ): Get the current time
minute( Specify time ): Get the current minute
second( Specify time ): Get the current second
week( Specify time ): Get the week ordinal of the current year
weekday( Specify time ): Get the day of the week
Backup of data table
It is a combination of creating tables and querying tables
grammar :
create table The new name of the table as select * from Original table name ;
Copy emp surface , The new table is named emp_copy
Copy dept surface , The new table is named dept_copy
see mydb All tables in
1. Group query
grammar :
group by Grouped fields having Filter conditions
group by deptno,sex
The rules :
1) There are several lines of fields with the same rule that can be grouped
2) After grouping the fields of the same rule, the result of single row and single column will be formed
3)having Filter conditions can be added selectively according to the situation
4) Multi field grouping group by Field 1, Field 2
2.SQL The execution order of the statement key :
from -----> where----->gorup by---->having ----->select ----->order by ---->limit
Data table field modification
describe Table name ;
1: Add column
alter table Table name add column Name type ;
Specify the location to add columns
alter table Table name add column Name type after Name ;
2: Delete column
alter table Table name drop column Name ;
3: rename table
alter table Table name rename to The new name of the table ;
4: Modify the column
alter table Table name change column Name New column names New data types ;
mysql User management and permission settings
1: stay root Create a new ordinary user under user
create user 'zs'@'localhost' identified by '1234';
2: View user permissions
show grants for 'zs'@'localhost';
grant usage on *.* to 'zs'@'localhost'
3: Grant user rights
grant create on a.* to 'zs'@'localhost'; Grant users the right to create libraries a jurisdiction
4: Reclaim user rights
revoke create on a.* from 'zs'@'localhost'; Recycle user created Libraries a jurisdiction
5: Operation permissions on Columns
grant alter on a.* to 'zs'@'localhost';
6: Grant users permission to create new users
grant create user on *.* to 'zs'@'localhost';
7: Refresh permission table
flush privileges;
8: Grant users ' Give yourself permission to another user ' Authority
grant create on a.* to 'B'@'localhost' with grant option; A
grant create on a.* to 'C'@'localhost' identified by '1234'; B A B C
边栏推荐
- 1.0-mq getting started and using
- Tencent music knowledge map search practice
- SaaS privatization deployment scheme
- Cross project measurement is a good helper for CTOs and PMOS
- 2022 "gold, silver and four" is a must for job hopping. You must know 100 questions in 2022 intermediate and advanced Android interview to realize your big factory dream
- Shell scripts: Variables
- Sonar series: continuous scanning through Jenkins integrated sonarqube (IV)
- R language momentum and Markowitz portfolio model implementation
- The latest promo! 1 minute to understand the charm of the next generation data platform
- Data query of server SQL. The most important chapter in database learning
猜你喜欢
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
[distributed system design profile (1)] raft
Global netizens Yuanxiao created a picture of appreciating the moon together to experience the creativity of Baidu Wenxin big model aigc
hashlib. Md5() function to filter out duplicate system files and remove them

Installing mysql8 under centos8
Interviewer: why does TCP shake hands three times and break up four times? Most people can't answer!

Docker failed to remotely access 3306 after installing MySQL

A simple file searcher

Jingxi Pinpin wechat applet -signstr parameter encryption

Illustrated with pictures and texts, 700 pages of machine learning notes are popular! Worth learning
随机推荐
couldn‘t be accessed by user ‘_ apt‘
2022 "gold, silver and four" is a must for job hopping. You must know 100 questions in 2022 intermediate and advanced Android interview to realize your big factory dream
How to buy the millions of medical insurance for children? How much is it a year? Which product is the best?
IPtables
HMS core actively explores the function based on hardware ear return, helping to reduce the overall singing delay rate of the singing bar by 60%
启牛学堂证券开户安全嘛?
R language quantile autoregressive QAR analysis pain index: time series of unemployment rate and inflation rate
Sqlmap for interface security testing
银河证券靠谱吗?开证券账户安全吗?
同花顺app是正规的吗?到底安不安全
Is it safe for qiniu school to open an account in 2022?
js(3)
"Space guard soldier" based on propeller -- geosynchronous geostationary orbit space target detection system
Installing and configuring redis under Linux
Bank digital transformation layout in the beginning of the year, 6 challenges faced by financial level structure and Countermeasures
Basic process of configuring utf8 in idea
Analysis and cleaning of kdevtmpfsi virus content
1.1-mq visual client preliminary practice
The secret of metaktv technology of sound network: 3D space sound effect + air attenuation + vocal blur
Feature Engineering in simple terms – a practice guide based on openmldb (Part 1)