How to export and import .sql files under Linux command

How to export and import .sql files under Linux command

This article describes how to export and import .sql files under Linux commands. Share with you for your reference, the details are as follows:

1. Export the database using the mysqldump command (note the installation path of mysql, which is the path of this command):

1. Export data and table structure:

mysqldump -u username -p password database name> database name.sql

#/usr/local/mysql/bin/mysqldump -uroot -p abc > abc.sql

After pressing Enter, you will be prompted to enter a password

2. Export only the table structure

mysqldump -u username -p password -d database name> database name.sql

#/usr/local/mysql/bin/mysqldump -uroot -p -d abc > abc.sql

Note: /usr/local/mysql/bin/ ---> mysql data directory

2. Import database

1. First create an empty database

mysql>create database abc;

2. Import database

Method 1:

(1) Select a database

mysql>use abc;

(2) Set the database encoding

mysql>set names utf8;

(3) Import data (pay attention to the path of the sql file)

mysql>source /home/abc/abc.sql;

Method 2:

mysql -u username -p password database name < database name.sql

#mysql -uabc_f -p abc < abc.sql

The second method is recommended for importing.

Note: There is a command line mode and sql commands

The above is the editor's method of exporting and importing .sql files under the Linux command. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to configure the display format of the Linux command prompt
  • How to switch from root to ordinary user to execute scripts or commands in Linux shell scripts
  • The meaning of the return value of the linux command
  • Two ways to change passwords in Linux through Shell script commands
  • Detailed explanation of mathematical operations examples in Linux command line
  • Solve the problem that all linux commands cannot be used

<<:  Detailed explanation of nginx server installation and load balancing configuration on Linux system

>>:  WeChat applet learning wxs usage tutorial

Recommend

How to get the dynamic number of remaining words in textarea

I encountered a case at work that I had never wri...

Introduction to the use of html base tag target=_parent

The <base> tag specifies the default address...

Use of Linux crontab command

1. Command Introduction The contab (cron table) c...

Demystifying the HTML 5 Working Draft

The World Wide Web Consortium (W3C) has released a...

Methods and steps for deploying go projects based on Docker images

Dependence on knowledge Go cross-compilation basi...

How to deploy Redis 6.x cluster through Docker

System environment: Redis version: 6.0.8 Docker v...

Solution to mysql login warning problem

1. Introduction When we log in to MySQL, we often...

What is em? Introduction and conversion method of em and px

What is em? em refers to the font height, and the ...

Implementation of FIFO in Linux process communication

FIFO communication (first in first out) FIFO name...

Why should the number of rows in a single MySQL table not exceed 5 million?

Today, let’s discuss an interesting topic: How mu...

Docker-compose image release process analysis of springboot project

Introduction The Docker-Compose project is an off...

Three ways to jump to a page by clicking a button tag in HTML

Method 1: Using the onclick event <input type=...

Detailed tutorial on installing SonarQube using Docker

Table of contents 1. Pull the image 1.1 Pull the ...