How can I import a database using command line?
up vote
1
down vote
favorite
I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip
. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.
When I run this command
mysql -u root -p spy < /var/www/backup.zip
nothing happens. A newline shows which starts with ->
.
What should I do now?
command-line mysql database
add a comment |
up vote
1
down vote
favorite
I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip
. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.
When I run this command
mysql -u root -p spy < /var/www/backup.zip
nothing happens. A newline shows which starts with ->
.
What should I do now?
command-line mysql database
You ran themysql
command insidemysql
?
– muru
Aug 23 '17 at 5:46
@muru Not sure what you mean exactly, but yes, as you see, there ismysql>
at the beginning of the line.
– stack
Aug 23 '17 at 5:47
1
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip
. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.
When I run this command
mysql -u root -p spy < /var/www/backup.zip
nothing happens. A newline shows which starts with ->
.
What should I do now?
command-line mysql database
I am using Ubuntu 14.04. I want to import my database which is located on the server /var/www/backup.zip
. Also I've SSH access using Putty. Noted that MySQL and phpMyadmin are installed on the server.
When I run this command
mysql -u root -p spy < /var/www/backup.zip
nothing happens. A newline shows which starts with ->
.
What should I do now?
command-line mysql database
command-line mysql database
edited Aug 23 '17 at 10:29
d a i s y
3,21982244
3,21982244
asked Aug 23 '17 at 5:40
stack
171118
171118
You ran themysql
command insidemysql
?
– muru
Aug 23 '17 at 5:46
@muru Not sure what you mean exactly, but yes, as you see, there ismysql>
at the beginning of the line.
– stack
Aug 23 '17 at 5:47
1
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26
add a comment |
You ran themysql
command insidemysql
?
– muru
Aug 23 '17 at 5:46
@muru Not sure what you mean exactly, but yes, as you see, there ismysql>
at the beginning of the line.
– stack
Aug 23 '17 at 5:47
1
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26
You ran the
mysql
command inside mysql
?– muru
Aug 23 '17 at 5:46
You ran the
mysql
command inside mysql
?– muru
Aug 23 '17 at 5:46
@muru Not sure what you mean exactly, but yes, as you see, there is
mysql>
at the beginning of the line.– stack
Aug 23 '17 at 5:47
@muru Not sure what you mean exactly, but yes, as you see, there is
mysql>
at the beginning of the line.– stack
Aug 23 '17 at 5:47
1
1
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26
add a comment |
3 Answers
3
active
oldest
votes
up vote
5
down vote
accepted
I believe the format is:
mysql -u username -p database_name < /path/to/file.sql
From within mysql:
mysql> use db_name;
mysql> source backup-file.sql;
well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?
– stack
Aug 23 '17 at 6:04
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago:)
)
– stack
Aug 23 '17 at 6:11
add a comment |
up vote
0
down vote
A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.
Read more here
You just need to add the missing semicolon.
New contributor
add a comment |
up vote
0
down vote
The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.
The second issue is that you have a zip file and not a SQL file so you need to unzip it first.
How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:
unzip -p /var/www/backup.zip | mysql -u root -p mydb
unzip -p
unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.
mysql -u root -p mydb
is going to prompt you for a password (the -p
without a value) and then attempt to pipe in the file data to mydb
- change the mydb
to your own database. You shouldn't specify the password in the command line as it then remains in your command history.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
I believe the format is:
mysql -u username -p database_name < /path/to/file.sql
From within mysql:
mysql> use db_name;
mysql> source backup-file.sql;
well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?
– stack
Aug 23 '17 at 6:04
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago:)
)
– stack
Aug 23 '17 at 6:11
add a comment |
up vote
5
down vote
accepted
I believe the format is:
mysql -u username -p database_name < /path/to/file.sql
From within mysql:
mysql> use db_name;
mysql> source backup-file.sql;
well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?
– stack
Aug 23 '17 at 6:04
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago:)
)
– stack
Aug 23 '17 at 6:11
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
I believe the format is:
mysql -u username -p database_name < /path/to/file.sql
From within mysql:
mysql> use db_name;
mysql> source backup-file.sql;
I believe the format is:
mysql -u username -p database_name < /path/to/file.sql
From within mysql:
mysql> use db_name;
mysql> source backup-file.sql;
edited Aug 23 '17 at 6:07
answered Aug 23 '17 at 6:02
George Udosen
18.2k94065
18.2k94065
well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?
– stack
Aug 23 '17 at 6:04
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago:)
)
– stack
Aug 23 '17 at 6:11
add a comment |
well what's the difference between yours (mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?
– stack
Aug 23 '17 at 6:04
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago:)
)
– stack
Aug 23 '17 at 6:11
well what's the difference between yours (
mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?– stack
Aug 23 '17 at 6:04
well what's the difference between yours (
mysql -u username -p database_name < /path/to/file.sql
) and mine (mysql -u root -p spy < /var/www/backup.zip
)?– stack
Aug 23 '17 at 6:04
3
3
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@stack that George intends that command to be run in the shell, and not inside mysql. (That's why the rest of the answer is headed by "from within mysql".)
– muru
Aug 23 '17 at 6:08
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago
:)
)– stack
Aug 23 '17 at 6:11
@muru Ah I see. thank you guys. (btw I think you could say so 30min ago
:)
)– stack
Aug 23 '17 at 6:11
add a comment |
up vote
0
down vote
A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.
Read more here
You just need to add the missing semicolon.
New contributor
add a comment |
up vote
0
down vote
A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.
Read more here
You just need to add the missing semicolon.
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.
Read more here
You just need to add the missing semicolon.
New contributor
A query normally consists of an SQL statement followed by a semicolon.
Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon.
Read more here
You just need to add the missing semicolon.
New contributor
New contributor
answered 4 hours ago
Danijela Kraljević
1
1
New contributor
New contributor
add a comment |
add a comment |
up vote
0
down vote
The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.
The second issue is that you have a zip file and not a SQL file so you need to unzip it first.
How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:
unzip -p /var/www/backup.zip | mysql -u root -p mydb
unzip -p
unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.
mysql -u root -p mydb
is going to prompt you for a password (the -p
without a value) and then attempt to pipe in the file data to mydb
- change the mydb
to your own database. You shouldn't specify the password in the command line as it then remains in your command history.
add a comment |
up vote
0
down vote
The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.
The second issue is that you have a zip file and not a SQL file so you need to unzip it first.
How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:
unzip -p /var/www/backup.zip | mysql -u root -p mydb
unzip -p
unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.
mysql -u root -p mydb
is going to prompt you for a password (the -p
without a value) and then attempt to pipe in the file data to mydb
- change the mydb
to your own database. You shouldn't specify the password in the command line as it then remains in your command history.
add a comment |
up vote
0
down vote
up vote
0
down vote
The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.
The second issue is that you have a zip file and not a SQL file so you need to unzip it first.
How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:
unzip -p /var/www/backup.zip | mysql -u root -p mydb
unzip -p
unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.
mysql -u root -p mydb
is going to prompt you for a password (the -p
without a value) and then attempt to pipe in the file data to mydb
- change the mydb
to your own database. You shouldn't specify the password in the command line as it then remains in your command history.
The main problem is that you're trying to run a bash command from within mysql. If you run that command at the regular terminal prompt the format of the command is correct.
The second issue is that you have a zip file and not a SQL file so you need to unzip it first.
How do I load a sql.gz file to my database? (on Server Fault) explains most of what you need. My answer there should work here too with a slight modification:
unzip -p /var/www/backup.zip | mysql -u root -p mydb
unzip -p
unzips to a pipe, so that you can pipe that into your database command. Make sure the zip file only contains one sql file.
mysql -u root -p mydb
is going to prompt you for a password (the -p
without a value) and then attempt to pipe in the file data to mydb
- change the mydb
to your own database. You shouldn't specify the password in the command line as it then remains in your command history.
answered 3 hours ago
icc97
16627
16627
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f948897%2fhow-can-i-import-a-database-using-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You ran the
mysql
command insidemysql
?– muru
Aug 23 '17 at 5:46
@muru Not sure what you mean exactly, but yes, as you see, there is
mysql>
at the beginning of the line.– stack
Aug 23 '17 at 5:47
1
How to import an SQL file using the command line in MySQL?
– d a i s y
Aug 23 '17 at 10:26