Skip to main content

Import and export mysql database using the console



Importing and exporting a mysql database using the console, I think, is the most versatile and most convenient way, compared to the same phpmyadmin, which you need to install and configure. And work with the console takes a minimum of time.

Of course, you must have access to SSH, either directly to the console, if this is your local computer, or to VNC.



Import

First you need to create a database .

  # mysql -u username -p database_name <db.sql 

Export


  # mysqldump -u username -p database_name > db.sql 

Replace the values ​​"username" and "database_name" with the user name and database name, respectively.

To export several databases, you can use the following command:

  # mysqldump -uroot -p -B base_1 base_2 base_3 > db.sql 

Where “base_1”, “base_2”, “base_3” are the names of the databases needed for copying, and “-B” is an indication that several databases are being copied.



Also, the mysqldump utility allows you to export all databases on the server into a single sql file. This is done by the command:

  # mysqldump -uroot -p -A> alldb.sql 


How do you rate the article?
Звёзд: 1Звёзд: 2Звёзд: 3Звёзд: 4Звёзд: 5 ( 14 ratings, average: 3.93 out of 5)
Loading...

” 15 Comments “ Import and export mysql database using the console

  1. In the one you specify.

    > db.sql saves to the current directory, where the command came from

    > /backup/mysql/db.sql saves to the dump folder, backup folders, for example

  2. There is in my opinion a mistake.
    Where exporting multiple DB pointer costs.
    I think it is worth fixing.

  3. Subjectively, it is better to use the following:

    mysql -u User Name -p Password -h Host Name Database

    in the mysql console that opens, enter:

    \. OurScript.sql

    then, to exit mysql, enter: \ q

    Seems to be something like that)

  4. this version of mysql doesn’t support 'multiple triggers with the same action when importing a database

  5. Tell me, what will the commands for creating a dump look like in the XP console? What are the differences from those given? There is no PHPmyadmin on the HAMRR server and there is no other way out
    thank

Add a comment

Your email will not be published.