user1188320
user1188320

Reputation: 575

how to import the database to mysql under linux?

The sql file named:bag.sql in /var/www/html/web(/var/www/html/web/bag.sql)

the current directory is [localhost web]i used mysql -uusername -p databasename > bag.sql

then let me input the password. i wait for long time, it doesn't show ok. why? how to import the database to mysql under centos.

Upvotes: 2

Views: 21559

Answers (6)

Parisa
Parisa

Reputation: 801

mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

source

Upvotes: 0

Ravikumar
Ravikumar

Reputation: 134

  1. Connect to mysql database server

    $ mysql -uusername -ppassword

  2. Check database exists are not

    $ show databases;

  3. If not create the same

    mysql>create database mydb;

    note: mydb is database name(Give your own).

  4. Check again for the database follow step 2.

  5. exit

  6. Import data to mydb(your own) database

    $ mysql -uusername -ppassword mydb < bag.sql

    note: your bag.sql is in the current directory from where you are executing the above command

  7. Check for imported data.

YES FOR LONG WAIT YOU NEED TO CHECK YOUR BAG.SQL FILE SIZE.

Symbol '$' is shell prompt

Upvotes: 2

danielrsmith
danielrsmith

Reputation: 4060

Let me offer up another alternative using pv

pv /path/to/file.sql | mysql -uUSERNAME -pPASSWORD -D DATABASE_NAME

This will show you a progress indicator for the import. If you have never used pv it is a piper viewer tool in linux.

Upvotes: 1

user319198
user319198

Reputation:

if you have already created database then use below steps to import data from .sql file

tell which database to use:

 use databasename;

Now give the source file path

 source /var/www/html/web/bag.sql;

Upvotes: 10

Kaustubh Karkare
Kaustubh Karkare

Reputation: 1101

you're using the wrong redirection operator. > is used for sending the output to a file, not taking input from a file. Use <.

Upvotes: 0

Joni
Joni

Reputation: 111349

You need mysql -uusername -p databasename < bag.sql.

<     Means "get the program's input from this file"
>     Means "write the program's output to this file"

Upvotes: 4

Related Questions