MySQL user management, common SQL statements, database backup recovery

Source: Internet
Author: User

MySQL User management

MySQL is divided into regular users and root users. These two types of users have different permissions.
New Normal User
There are 3 ways to build a user in the MySQL database:
Use the Create USER statement to make new users;
Insert the user directly in the Mysql.user table;
Use the GRANT statement to create a new user;

Grant Command
grant all on *.* to ‘user1‘@‘192.168.71.131‘ identified by ‘123456‘;

All means all permissions.
. Represents all libraries, the preceding represents the library name, and the following represents all the tables
' User1 ' @ ' 192.168.71.131 ' specifies the source IP of 192.168.71.131, which allows all IP words to use%, which indicates wildcard characters. The user created is UESR1

You can also use Locahost
grant SELECT,UPDATE,INSERT on db1.* to ‘user2‘@‘192.168.71.132‘ identified by ‘passwd‘;

Create a user2 normal user, and the source IP is 192.168.71.131, the library permission for the specified DB1 is Select,update,insert

View the user's authorization, here is the command to query the UESR1 user's authorization
show grants for [email protected]\G

Common SQL statements

To view the number of rows in a table in a library
select count(*) from mysql.user;

See all the content
select * from mysql.db\G;

Query fields

select db from mysql.db;select db,user from mysql.db;

Fuzzy query
select * from mysql.db where host like ‘192.168.%‘;

Insert a data
insert into db1.t1 values (1, ‘abc‘);

Update data
update db1.t1 set name=‘aaa‘ where id=1;

Empty a table

truncate table db1.t1;drop table db1.t1;

Empty Library
drop database db1;

MySQL Database backup recovery

Backup Library
mysqldump -uroot -p‘testpasswd1.3‘ mysql > /tmp/mysql.sql;

Recovery Library
mysql -uroot -p‘testpasswd1.3‘ mysql < /tmp/mysql.sql;

Backup table
mysqldump -uroot -p‘testpasswd1.3‘ mysql user > /tmp/user.sql;

Recovery table
mysql -uroot -p‘testpasswd1.3‘ mysql < /tmp/user.sql

Back Up all libraries
mysqldump -uroot -p -A >/tmp/123.sql

Back up table structure only
mysqldump -uroot -p‘testpasswd1.3‘ -d mysql > /tmp/mysql.sql

MySQL user management, common SQL statements, database backup recovery

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.