当前位置:网站首页>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
边栏推荐
- Cisco vxlan configuration
- Inno setup the simplest user-defined interface effect
- 【LeetCode】236. Nearest common ancestor of binary tree
- Who is promoting the new inflection point of audio and video industry in 2022?
- Cisco VXLAN配置
- [Blue Bridge Road -- bug free code] DS1302 time module code analysis
- [untitled] user defined function
- Leetcode search insert location
- 86. separate linked list
- [road of system analyst] collection of wrong topics in Project Management Chapter
猜你喜欢
Finally someone can make the server so straightforward
剑指 Offer 18. 删除链表的节点
Lantern Festival | maoqiu technology and everyone "guess riddles and have a good night"
09- [istio] istio service entry
MySQL 索引
【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
Solidity - 安全 - 重入攻击(Reentrancy)
Voting vault: a new primitive for defi and Governance
What kind of answer has Inspur given in the big AI model landing test?
强烈推荐十几款IDEA开发必备的插件
随机推荐
Xi'an Jiaotong automation control theory test simulation question [standard answer]
We strongly recommend more than a dozen necessary plug-ins for idea development
You don't know how to deduce the location where HashSet stores elements?
Database SQL language 06 single line function
[road of system analyst] collection of wrong topics in Project Management Chapter
Word frequency statistics (string, list)
14x1.5cm vertical label is a little difficult, VFP calls bartender to print
The average salary of software testing in 2022 has been released. Have you been averaged?
Xctf attack and defense world crypto advanced area
What indicators should safety service engineers pay attention to in emergency response?
Xi'an Jiaotong 21st autumn "computerized accounting" online homework answer sheet (I) [standard answer]
Database SQL language 05 SQL exercise
How to print pthread_ t - How to print pthread_ t
I have been working as a software testing engineer for 5 years, but I was replaced by an intern. How can I improve myself?
Detailed explanation of issues related to SSL certificate renewal
Stack overflow caused by C # using protobuf stack overflow
What do you think of the deleted chat records? How to restore the deleted chat records on wechat?
Force deduction exercise -- deleting repeated items in ordered sequence 1.0
MySQL高级SQL语句
Xiaosha's lunch