Common MySQL commands and backup and restore

1. Create user:
# Specify ip: 192.118.1.1 alex user login
create user 'alex'@'192.118.1.1' identified by '123';
# Specify ip: 192.118.1. Alex user login
create user 'alex '@' 192.118.1.% 'Identified by' 123 ';
# specify any ip alex user login
create user' alex '@'% 'identified by' 123 ';

2. Delete user
drop user 'user name' @ 'IP address';


3. Modify user
rename user 'user name' @ 'IP address' to 'new user name' @ 'IP address';

4. Modify the password
set password for 'user name' @ 'IP address' = Password ('new password');


#View permissions show grants for 'user' @ 'IP address'

#Authorize alex users to only query, insert and update the db1.t1 file
grant select, insert, update on db1.t1 to "alex" @ '%';

# Indicates that all permissions are granted, except for the grant command, which is only available for root. alex user has any operation
on the t1 file under db1 grant all privileges on db1.t1 to "alex" @ '%';
#alex user performs any operation
on files in the db1 database grant all privileges on db1. * to "alex" @ '%';
#alex users have any operations on all files in the database
grant all privileges on *. * to "alex" @ '%';

#Cancel permission

# Cancel any operation of alex user on db1 t1 file
revoke all on db1.t1 from 'alex' @ "%";

# Cancel all permissions of all tables of database db1 from alex user from remote server

revoke all on db1.* from 'alex'@"%";


Revoke all privileges on all tables in all databases of alex user from remote server. Revoke all privileges on *. * From 'alex' @ '%';

# Backup: data table structure + data, b1.sql is the name of the output backup file
, and a sql file is output after backup. It exists in the bin directory of mysql
mysqldump -u root db1> db1.sql -p


# Backup: data table structure
mysqldump -u root -d db1> db1.sql -p

#Import existing data to a database
# 1. First create a new database
create database db10;
# 2. Import the existing database file into the db10 database
mysqldump -u root -d db10 <db1.sql -p

#The above backup and restore cmd command backup and restore, you can also use the Navicat for MySQL tool to backup and restore

Guess you like

Origin www.cnblogs.com/Lxxv5/p/12752149.html