当前位置:网站首页>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
边栏推荐
- 领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
- [ansible series] fundamentals -01
- Database SQL language 04 subquery and grouping function
- UE4_ Editor UMG close window cannot destroy UMG immediately
- leetcode763. Divide letter interval
- Simple use of qlistview of QT (including source code + comments)
- Attempt to redefine 'timeout' at line 2 solution
- 剑指 Offer 22. 链表中倒数第k个节点
- Rotating box target detection mmrotate v0.3.1 getting started
- Xijiao 21 autumn "motor and drive" online homework answer sheet (I) [standard answer]
猜你喜欢

Sound net, debout dans le "sol" de l'IOT

UE4_ Editor development: highlight the UI making method according to the assets dragged by the mouse (1)

Access is denied encountered when vfpbs calls excel under IIS
![[ansible series] fundamentals -01](/img/b4/1f3284338c75acb5259849a45bbfbe.jpg)
[ansible series] fundamentals -01

云服务器部署 Web 项目

Dynamic programming -- gliding wing of the strange thief Kidd

AI大模型落地大考,浪潮交出了怎样的答卷?

MySQL数据库用户管理

English语法_形容词/副词3级-最高级

Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
随机推荐
Cisco vxlan configuration
MySQL 索引
动态规划--怪盗基德的滑翔翼
Sword finger offer 29 Print matrix clockwise
Solidity - Security - reentrancy attack
After getting these performance test decomposition operations, your test path will be more smooth
[GPU] basic operation
Use of tornado template
OSPF - authentication and load balancing summary (including configuration commands)
Learning automation ppt
Codeforces C. Andrew and Stones
ECS deployment web project
Sound network, standing in the "soil" of the Internet of things
Who is promoting the new inflection point of audio and video industry in 2022?
Do you know how to show the health code in only 2 steps
UML tools
Lantern Festival | maoqiu technology and everyone "guess riddles and have a good night"
2022年,谁在推动音视频产业的新拐点?
Projet Web de déploiement du serveur Cloud
Related applications of priority queue