How to import into MySQL database from command line?

4

I'm trying to import a more or less large database ( 1Gb ) using PHPMyAdmin .
The process is too slow and always cuts.

Is there a way to import a database MySQL from the command line?

    
asked by Marcos 27.12.2018 в 15:35
source

2 answers

2

Using mysqldump I was able to import a file sql directly in the database.

On Linux or Windows cmd :

$ mysql -u <usuario> -p <nombreBaseDeDatos> < <archivo.sql>

Indicating the password ( insecure ):

$ mysql -u <usuario> -p<contraseña> <nombreBaseDeDatos> < <archivo.sql>

On Windows Powershell

$ Get-Content <archivo.sql> | mysql -u <usuario> -p <nombreBaseDeDatos>

Indicating the password ( insecure ):

$ Get-Content <archivo.sql> | mysql -u <usuario> -p<contraseña> <nombreBaseDeDatos>

Reference:

answered by 27.12.2018 в 15:35
2

The answer I will give is not proven with files .sql of that size 1GB however I share it with you

  • Locate your .sql file within Unit C, for example with a descriptive name
  • C:.
    ├───backup.sql
    
  • Later from the command line of your mysql you execute the following
  • mysql -u root -p
    password: *******
    
    mysql> SOURCE C:/backup.sql;
    

    The console depending on the number of tables should be returning something similar to the following

    Query OK, 0 rows affected (0.11 sec)
    
    Query OK, 0 rows affected (0.01 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    Query OK, 0 rows affected, 1 warning (0.10 sec)
    
    Query OK, 0 rows affected (0.04 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    Query OK, 13 rows affected (11.51 sec)
    
    Query OK, 1 row affected (0.22 sec)
    
    .................................. more
    

    CLARIFICATIONS

  • If the file .sql already contains in its structure the statements of:
  • CREATE DATABASE

    and

    USE tuBaseDatos

    then it is not necessary to create it but simply execute said command

  • If, on the other hand, the database does not exist in the database manager and there is no declaration in the backup .sql then:
  • First you must run

    CREATE DATABASE TubaseDatos;
    

    And later

    USE TubaseDatos;
    

    so that in the end we execute

    SOURCE C:/backup.sql
    
        
    answered by 27.12.2018 в 15:45