当前位置:网站首页>Advanced operation of MySQL database basic SQL statement tutorial
Advanced operation of MySQL database basic SQL statement tutorial
2022-06-26 15:08:00 【1024 Q】
Preface :
One . Clone table
1.1 Cloning method 1 ( Clone tables and contents separately )
1.2 Cloning method 2 ( Copy the table with the contents )
Two . Clear the table , Delete all data in the table
2.1 Method 1
2.2 Method 2
2.3 Little knot drop,truncate,eleted Comparison of
3、 ... and . Create a temporary table
Four . User management
4.1 A new user
4.2 Create users with clear text passwords
4.3 Create a database using ciphertext
5、 ... and . View user information
6、 ... and . Rename user
7、 ... and . Delete user
8、 ... and . Password management
8.1 Change the current user password
8.2 Change the password of other users
8.3 forget root password
8.3.1 to root Set the password
Nine . Database authorization
9.1 About Authorization
9.2 to grant authorization
9.2.1 Authorization list
9.3 Database authorization
9.4 Remote login authorization ( Use navicat Remote login )
9.5 Revoke authority
Ten . summary
Preface :Got it MySQL Basic statement of database , In this chapter, learn about its advanced operation , Including adding, deleting and giving corresponding permissions to users
One . Clone table 1.1 Cloning method 1 ( Clone tables and contents separately )#create table The new name of the table like Replicated table name ; Copy the format , Can copy the format of a table to a new table , But the contents cannot be copied insert into The new name of the table select * from Replicated table name ; Copy the contents of the original table to the new table 


create table The new name of the table (select * from Replicated table name ) Data structure and data can be copied together 
delete from naixu1;#DELETE After emptying the table , There are deleted record entries in the returned result ;delete When working, delete record data line by line ; If there is a self growing field in the table , Use DELETE FROM After deleting all records , The record added here will be changed from the original largest record id Continue to write data automatically later 


truncate table naixu1;#TRUNCATE After emptying the table , No deleted entries are returned :TRUNCATE The work is to rebuild the table structure as it is, so in terms of speed TRUNCATE than DELETE Empty table quick use TRUNCATE TABLE After clearing the data in the table ,id From 1 Start re recording 
| drop | truncate | delete |
| Belong to DDL | Belong to DDL | Belong to DML |
| Cannot roll back | Cannot roll back | Roll back |
| Don't bring where | Don't bring where | Can take where |
| Table content and structure delete | Table contents delete | The table structure is in , The content of the table depends on where Implementation |
| Delete fast | Delete fast | Slow to delete , Need to delete line by line |
3、 ... and . Create a temporary tablesummary :
Use when you no longer need a table drop When you want to delete some data rows, use delete, And bring them up. where Clause to keep the table and delete all data truncate Delete speed :drop>truncate> delete Security delete best
## Add temporary table niaxu3create temporary table naixu3 (id int(4) zerofill primary key auto_increment,name varchar(10) not null,cardid int(18) not null unique key,hobby varchar(50));## View all tables in the current library show tables; ## Add data to temporary table insert into test03 values(1,'hehe',12345,' Look at the beauty '); ## View all data in the current table select * from naixu3;## Exit database quit ## Log in again and view mysql -u root -p## View all data in the temporary table created before , Found to have been automatically destroyed select * from naixu3; 

CREATE USER ' user name '@' Source address ' [IDENTIFIED BY [PASSWORD] ' password '];#‘ user name ': Specify the user name that will be created #‘ Source address ': Specify which hosts the newly created user can log on to , You can use IP Address 、 Network segment 、 The form of host name , Available to local users localhost, Allow any host to log in. Wildcards are available %#‘ password ': If plaintext password is used , Direct input ' password ', Inserted into the database by Mysql Automatic encryption ;####### If you use an encrypted password , You need to use it first SELECT PASSWORD(‘ password '); Get ciphertext , Then add... To the statement PASSWORD ‘ Ciphertext ';# If you omit “IDENTIFIED BY” part , Then the user's password will be empty ( Not recommended )4.2 Create users with clear text passwords create user 'nannan'@'localhost' identified by '123455';

The created user is saved in mysql Database user table use mysql; # Use mysql library select User from user;
rename user 'nannan'@'localhost' to 'lnhs'@'localhost';# Will the user nannan Renamed as lnhs
drop user 'chenchen'@'localhost';# Delete user chenchen
set password = password('123456');
set password for 'naixu'@'localhost' = password('123456');
Modify the configuration file , Add the configuration , Password free login MySQLvim /etc/my.cnfskip-grant-tables # add to , Log in mysql Not applicable to authorization form 

update mysql.user set authentication_string = password('123456') where user='root';flush privileges; # Refresh Log in to the database and modify it again my.conf The configuration file , Comment out the previously added configuration command , And restart the service again to log in with a new password 

GRANT sentence : It is specially used to set the access rights of database users . When the specified user name does not exist ,GRANT Statement will New users will be created ; When the specified user name exists ,GRANT Statement is used to modify user information .
9.2 to grant authorizationGRANT Permission list ON Database name / Table name TO ' user name '@' Source address ' [IDENTIFIED BY ' password '];| Permission list | Used to list various database operations authorized for use , Separated by commas , Such as “select,insert,update”. Use “all” Indicates all permissions , You can authorize any operation . |
| Database name . Table name | The name of the database and table used to specify the authorization operation , You can use wildcards |
| user name @ Source address | Used to specify the user name and the client address to which access is allowed , Who can connect 、 Where can I connect . The source address can be a domain name 、IP Address , You can also use “%” wildcard , Represents all addresses in an area or network segment , Such as “%.accp.com”、“192.168.80.%” etc. . |
| IDENTIFIED BY | Used to set the password string used by users when connecting to the database . When creating a new user , If you omit “IDENTIFIED BY” part , Then the user's password will be empty . |
| jurisdiction | function |
| select | Query data |
| insert | insert data |
| update | Update data |
| delete | Delete data |
| create | Create a library 、 surface |
| drop | Delete Library 、 surface |
| index | Index |
| alter | Change table properties |
| event | event |
| trigger on | Create trigger |
show grants for [email protected];# View user permissions 
Specify which database or table users can view , Others cannot access
grant select on hehe.* to [email protected];# user nannan Only hehe Query permission of all tables under the library 
Switch users for authentication


grant all on *.* to 'nannan'@'%' identified by '123456';


revoke select on hehe.* from [email protected];
Switch access again , You have no authority

In this chapter, I will explain MySQL High level statement for , Includes how to clone tables , How to add, delete, and modify users and how to set user permissions , In general, just remember 3 Just click add, delete and modify
This is about MySQL The database is basically SQL This is the end of the advanced operation article of the statement tutorial , More about MySQL SQL Statement advanced operation content please search the previous articles of the software development network or continue to browse the following related articles. I hope you can support the software development network in the future !
边栏推荐
- 15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
- 10分钟了解BIM+GIS融合,常见BIM数据格式及特性
- Is the QR code for account opening given by the manager of the securities firm safe? Who can I open an account with?
- Unity C # e-learning (IX) -- wwwfrom
- Mathematical modeling of war preparation 30 regression analysis 2
- 关于 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error 解决方案(已解决)
- qt下多个子控件信号槽绑定方法
- Restcloud ETL extraction de données de table de base de données dynamique
- 打新债注册开户安全吗,有没有什么风险?
- Redis cluster re fragmentation and ask command
猜你喜欢

Talk about the RPA direction planning: stick to simple and valuable things for a long time

15 bs对象.节点名称.节点名称.string 获取嵌套节点内容

Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution

Smoothing data using convolution

Authoritative announcement on the recruitment of teachers in Yan'an University in 2022

Use abp Zero builds a third-party login module (II): server development

Bank of Beijing x Huawei: network intelligent operation and maintenance tamps the base of digital transformation service

【雲原生】 ”人人皆可“ 編程的無代碼 iVX 編輯器

文献1

View touch analysis
随机推荐
Optimizing for vectorization
nvidia-smi 报错
php文件上传00截断
小程序:uniapp解决 vendor.js 体积过大的问题
It's natural for the landlord to take the rent to repay the mortgage
Unity C # e-learning (VIII) -- www
Unity C# 网络学习(九)——WWWFrom
BLE抓包调试信息分析
R language dplyr package summary_ The at function calculates the mean and median of multiple data columns (specified by vectors) in the dataframe data, and specifies na RM parameter configuration dele
The DOTPLOT function in the epidisplay package of R language visualizes the frequency of data points in different intervals in the form of point graphs, specifies the grouping parameters with the by p
R language dplyr package bind_ The rows function merges the rows of the two dataframes vertically. The final number of rows is the sum of the rows of the original two dataframes (combine data frames)
R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and use agg
Deployment of kubernetes' controller
关于 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error 解决方案(已解决)
Use abp Zero builds a third-party login module (I): Principles
C语言刷题随记 —— 乒乓球比赛
Pod scheduling of kubernetes
Unity C# 网络学习(十)——UnityWebRequest(二)
[async/await] - the final solution of asynchronous programming
Idea shortcut key