MySQL database account creation, authorization, data export and import operation examples

MySQL database account creation, authorization, data export and import operation examples

This article describes the examples of creating accounts, authorization, data export and import operations in MySQL database. Share with you for your reference, the details are as follows:

1. Account creation and authorization

grant all privileges on *.* to 'yangxin'@'%' identified by 'yangxin123456' with grant option;
  • privileges: means all permissions are granted to the user. You can also specify specific permissions, such as: SELECT, CREATE, DROP, etc.
  • on: indicates which databases and tables these permissions are effective for. The format is database name.table name. Writing "*" here means all databases and all tables. If I want to specify that permissions be applied to the user table in the test library, I can write: test.user
  • to: The user to whom the permission is granted. Format: "user name"@"login IP or domain name". % means there is no restriction and you can log in from any host. For example: "yangxin"@"192.168.0.%", which means that the user yangxin can only log in in the 192.168.0 IP segment
  • identified by: specifies the user's login password
  • with grant option: allows users to grant their permissions to other users

2. Check user permissions

show grants for root;

3. Reclaim permissions

revoke create on *.* from 'yangxin';

4. Delete User

drop user test;

5. Change password

1> Update mysql.user table

# Before mysql5.7 update mysql.user set password=password('123456') where user='root';
# After mysql5.7 update mysql.user set authentication_string=password('123456') where user='root';

2> Use the set password command

grammar:

set password for 'user name'@'login address'=password('password')

3>mysqladmin

Syntax: mysqladmin -u username -p old password password new password

Remember to refresh permissions:

flush privileges;

Data export:

1. Export structure but not data

mysqldump -d database name -uroot -p > xxx.sql

2. Export data but not structure

mysqldump -t database name -uroot -p > xxx.sql

3. Export data and table structure

mysqldump database name -uroot -p > xxx.sql

4. Export the structure of a specific table

mysqldump -uroot -p -B database name --table table name> xxx.sql
#mysqldump [OPTIONS] database [tables]

Import data:

mysql -uroot -p database name < file name

or:

Then select the database to be imported:

#use database;
#source /tmp/xxx.sql

Readers who are interested in more MySQL-related content can check out the following topics on this site: "Summary of MySQL Index Operation Skills", "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills".

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • Pycharm remotely connects to the server and runs and debugs
  • Pycharm remote connection server debugging tensorflow cannot load problem
  • The whole process of Pycharm connecting to the remote server and remote debugging
  • Pycharm synchronous remote server debugging method steps
  • mysql create database, add users, user authorization practical method
  • Pycharm remote debugging and MySQL database authorization issues

<<:  How to implement web stress testing through Apache Bench

>>:  Detailed steps to install Sogou input method on Ubuntu 20.04

Recommend

How to use axios request in Vue project

Table of contents 1. Installation 2. There is no ...

JS realizes the effect of Baidu News navigation bar

This article shares the specific code of JS to ac...

How to install Postgres 12 + pgadmin in local Docker (support Apple M1)

Table of contents introduce Support Intel CPU Sup...

Summary of three rules for React state management

Table of contents Preface No.1 A focus No.2 Extra...

Explanation of several ways to run Tomcat under Linux

Starting and shutting down Tomcat under Linux In ...

Implementation of docker redis5.0 cluster cluster construction

System environment: Ubuntu 16.04LTS This article ...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

Implementation of tomcat image created with dockerfile based on alpine

1. Download the alpine image [root@docker43 ~]# d...

Manually install mysql5.7.10 on Ubuntu

This tutorial shares the process of manually inst...

Example of usage of keep-alive component in Vue

Problem description (what is keep-alive) keep-ali...

How to handle concurrent updates of MySQL data

Will UPDATE lock? Will the SQL statement be locke...

js method to delete a field in an object

This article mainly introduces the implementation...

How to deploy MySQL 5.7 & 8.0 master-slave cluster using Docker

> Deploy MySQL 5.7 cluster master & slave ...

Detailed explanation of TS object spread operator and rest operator

Table of contents Overview Object rest attribute ...

HTML page common style (recommended)

As shown below: XML/HTML CodeCopy content to clip...