当前位置:网站首页>Mysql database user management
Mysql database user management
2022-06-30 05:53:00 【Sxiny Xin】
One 、 Data table operation
1.1 Clone table
Generate the data records of the table into a new table
# adopt LIKE Method , Copy lyong Table structure generation lyong_bak surface
create table lyong_bak like lyong;
# Import data
insert into lyong_bak (select * from lyong); # Backup data content

There is no data in the table after backup , Just cloned the structure of the table 
take xy The data in is cloned into the backup xy_bak In the table 
Method 2 、 Import content when creating
create table lyong_bak02 (select * from lyong);

# Get the table structure of the data table 、 Index and other information
show create table lyong_bak\G;

1.2 Clear the table
Delete all data in the table
1.2.1deldte Delete
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 newly added record will be changed from the original largest record ID Continue to write the record automatically later .
#delete from Table name ;
delete from lly;
insert into lly(student_name,cardid,hobby) values('xyz',123456789,' nanjing ')
-> ;

1.2.2 truncate Delete
TRUNCATE After emptying the table , No deleted entries are returned ;TRUNCATE When working, the table structure is rebuilt as it is , So in terms of speed TRUNCATE than DELETE Empty the watch, quick ; Use TRUNCATE TABLE After clearing the data in the table ,ID From 1 Start re recording .
truncate table info;
insert into lly(student_name,cardid,hobby) values('llly',654321,' Shanghai ');
1.2.3 Create a temporary table
After the temporary table is created successfully , Use SHOW TABLES The command cannot see the created temporary table , The temporary table will be destroyed after the connection exits .
If before exiting the connection , You can also perform operations such as adding, deleting, modifying, and querying , For example, use DROP TABLE Statement to manually and directly delete the temporary table .
## Add temporary table lyong01
create temporary table lyong01 (
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,'zhangsan',123456789,'watch a film');
## View all data in the current table
select * from lyong01;
## 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 lyong01;
Two 、 User management
2.1 A new user
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 )
2.1.1 Create user using plaintext
CREATE USER 'liy'@'localhost' IDENTIFIED BY '123456';


2.1.2 Use ciphertext to create users
select password(‘123456’);
create user ‘zxy’@‘localhost’ identified by password ‘*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1’;
View user information
The created user is saved in mysql Database user table
use mysql
select user,authentication_string,host from user;
2、 View user information
use mysql;
select User,authentication_string,Host from user;
3、 Rename user
rename user 'sxy'@'localhost' to 'shixy'@'localhost';
select user,authentication_string,host from user;
4、 Delete user
drop user 'shixy'@'localhost';
select user,authentication_string,host from user;

3、 ... and 、 Database user authorization
1、 Grant authority
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 create a new user ; When the specified user name exists ,GRANT Statement is used to modify user information .
GRANT 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 “”. for example , Use “kgc.” The object representing the authorization operation is kgc All the tables in the database .
‘ 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 .
2、 Database authorization
show grants for [email protected];
# View user permissions
Specify which database users can view / surface , No access to other databases
grant select on test.* to [email protected];
# user yong Only test Query permission of all tables under the library
边栏推荐
- Simple use of qlistview of QT (including source code + comments)
- Related applications of priority queue
- Turn off automatic outlining in Visual Studio - turning off automatic outlining in Visual Studio
- [deep learning] data segmentation
- 动态规划--怪盗基德的滑翔翼
- Database SQL language 05 SQL exercise
- 从零开发 stylelint规则(插件)
- Sound network, standing in the "soil" of the Internet of things
- Use of tornado template
- Codeforces C. Andrew and Stones
猜你喜欢

Voting vault: a new primitive for defi and Governance

How to automatically renew a token after it expires?

Xctf attack and defense world crypto advanced area

About modifying dual system default startup item settings

After getting these performance test decomposition operations, your test path will be more smooth
![[MD editing required] welcome to the CSDN markdown editor](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[MD editing required] welcome to the CSDN markdown editor

8 ways to earn passive income

What indicators should safety service engineers pay attention to in emergency response?

Delete the repeating elements in the sorting list (simple questions)

【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
随机推荐
Luogup2756 pilot pairing scheme problem (maximum flow)
Turn off automatic outlining in Visual Studio - turning off automatic outlining in Visual Studio
8 ways to earn passive income
[Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
Finally someone can make the server so straightforward
Codeforces B. MEX and Array
雲服務器部署 Web 項目
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
Shopping list--
Solidy - fallback function - 2 trigger execution modes
Online assignment of C language program design in the 22nd spring of Western Polytechnic University
What indicators should safety service engineers pay attention to in emergency response?
How to write a thesis
Intelligent deodorizer embedded development
86. 分隔链表
Xi'an Jiaotong 21st autumn "computerized accounting" online homework answer sheet (I) [standard answer]
【LeetCode】236. Nearest common ancestor of binary tree
MySQL高级SQL语句
English grammar_ Adjective / adverb Level 3 - superlative
Vfpbs uploads excel and saves MSSQL to the database