当前位置:网站首页>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 !
边栏推荐
- 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
- 杜老师说网站更新图解
- Cache page keepalive use in Vue
- vsomeip3 双机通信文件配置
- R language uses ggplot2 to visualize the results of Poisson regression model and count results under different parameter combinations
- Excel-VBA 快速上手(二、条件判断和循环)
- Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
- 使用 Abp.Zero 搭建第三方登录模块(一):原理篇
- The tablestack function of the epidisplay package of R language makes a statistical summary table (descriptive statistics of groups, hypothesis test, etc.), does not set the by parameter to calculate
- Unity C# 网络学习(十)——UnityWebRequest(一)
猜你喜欢
View触摸分析
Restcloud ETL extracting dynamic library table data
获取两个dataframe的交并差集
The engine "node" is inconsistent with this module
Mark一下 Unity3d在Inspector中选中不了资源即Project锁定问题
qt下多个子控件信号槽绑定方法
About selenium common. exceptions. Webdriverexception: message: an unknown server side error solution (resolved)
Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution
vsomeip3 双机通信文件配置
MySQL数据库基本SQL语句教程之高级操作
随机推荐
Unity C # e-learning (10) -- unitywebrequest (2)
Attention meets geometry: geometry guided spatiotemporal attention consistency self supervised monocular depth estimation
Informatics Olympiad all in one 1400: count the number of words (string matching)
Unity C # e-learning (IX) -- wwwfrom
Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
Unity C # e-learning (VIII) -- www
R语言dplyr包bind_rows函数把两个dataframe数据的行纵向(竖直)合并起来、最终行数为原来两个dataframe行数的加和(Combine Data Frames)
一篇抄十篇,CVPR Oral被指大量抄袭,大会最后一天曝光!
English语法_形容词/副词3级 - 原级句型
Redis集群消息
Keil4打开单片机工程一片空白,cpu100%程序卡死的问题解决
php文件上传00截断
Get the intersection union difference set of two dataframes
Optimizing for vectorization
北京银行x华为:网络智能运维夯实数字化转型服务底座
网上找客户经理办理股票开户安全吗??
【雲原生】 ”人人皆可“ 編程的無代碼 iVX 編輯器
The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
C语言刷题随记 —— 乒乓球比赛
人力资源导出数据 excel VBA