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

Web page text design should be like smart girls wearing clothes

<br />"There are no ugly women in the w...

Docker container orchestration implementation process analysis

In actual development or production environments,...

Multi-service image packaging operation of Dockerfile under supervisor

Writing a Dockerfile Configure yum source cd /tmp...

Install Python virtual environment in Ubuntu 18.04

For reference only for Python developers using Ub...

Summary of the Differences between SQL and NoSQL

Main differences: 1. Type SQL databases are prima...

JavaScript to achieve dynamic color change of table

This article shares the specific code for JavaScr...

How to build a MySQL high-availability and high-performance cluster

Table of contents What is MySQL NDB Cluster Preli...

How to uninstall MySQL 5.7 on CentOS7

Check what is installed in mysql rpm -qa | grep -...

Detailed steps for installing MySQL using cluster rpm

Install MySQL database a) Download the MySQL sour...

How to switch directories efficiently in Linux

When it comes to switching directories under Linu...

mysql data insert, update and delete details

Table of contents 1. Insert 2. Update 3. Delete 1...

Analysis and solution of a.getAttribute(href,2) problem in IE6/7

Brief description <br />In IE6 and 7, in a ...

Detailed example of using useState in react

useState useState adds some internal state to a c...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...

HTML table only displays the outer border of the table

I would like to ask a question. In Dreamweaver, I...