Get the App
SLTechnology News&Howtos  ›  Database  › 

How to import and export mysql database in Linux

Shulou Source: shulou.com Published: 2022-05-31 22:31:37 09月19日 Update

This article introduces you how to import and export mysql database in Linux, the content is very detailed, interested friends can refer to it, I hope it can help you.

Linux is a free-to-use and freely distributed UNIX-like operating system, is a POSIX-based multi-user, multitasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.

1. Export database with mysqldump command

(Note: first cd to mysql run path, and then execute a command):

1. Export data and table structure:

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

Note that my server configuration permissions are special, so I need to use muysqldump -h 127.0.0.1-u username-p password database name> database name you named yourself.sql

mysqldump -uroot -p dbname > dbname .sqlmysqldump -h 127.0.0.1 -uroot -p dbname > dbname .sql

After exporting, you can log in to ftp and find this sql file and download it directly, or download it with scp command.

Enter will prompt for password

2. Export only table structure

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

For example: mysqldump -uroot -p -d dbname > dbname.sql

II. Import database

First, create an empty database.

mysql>create database dbname ;

2. Import database

Method 1:

(1) Select database

mysql>use dbname ; e.g. mysql>use hljz

(2) Set database code

mysql>set names utf8;

(3) Import data (note the path of sql file)

mysql>source /home/xxxx/dbname .sql; /home/xxxx/dbname.sql is the path of your database file on the server. How to import and export mysql database in Linux is shared here. I hope the above content can be of some help to everyone. You can learn more. If you think the article is good, you can share it so that more people can see it.

Tags: Data database password user command file user name system path guide operating system content more server structure help service run good special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Docker Shulou Tech Info Linux