executing a .sql file in command line - mysql

Doing
mysql -uroot -p -e source F:\code\mysql\mysql-data\myHfs\test.sql
gives : ERROR 1049 (42000): Unknown database 'f:\code\mysql\mysql-data\myhfs\test.sql'
But if i go inside the mysql command promt with just the mysql -uroot -p and then type in source F:\code\mysql\mysql-data\myHfs\test.sql , i get the proper output.
the content of the above file being :
use gregs_list;
show tables;
select * from clown_info;
Edit : doing mysql -uroot -p < "F:\code\mysql\mysql-data\myHfs\test.sql" -t seems to solve the problem.

http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html
mysql -uroot -p < "F:\code\mysql\mysql-data\myHfs\test.sql"

Related

Mysql restore file .dump database

I execute the command : mysql -u user -p -h localhost bd_new < bd_dump.dump. Dont restore the bd and dont show error message.
I use other code: mysql -u root -p bd_new < bd_dump.dump and it happens like previus one.
The trouble are a .dump?

Mysql restore issue

I used to have mysql 5.6 server. I backed up with like this command.
mysqldump -u Myuser -pMypasswor Mydatabase > C:\backups\Mydatabase.sql
I removed Mysql 5.6 and installed 5.5 version.
Now I try to restore my database but it fails. Firstly I tried this
mysqldump -u Myuser -pMypasswor Mydatabase < C:\backups\Mydatabase.sql
Afterwards on Cmd Connected with
mysql -u Myuser -pMypassword
Mydatabase < C:\backups\Mydatabase.sql
I got this error
ERROR:
Unknown command '\a'.
ERROR:
Unknown command '\m'.
ERROR:
Unknown command '\I'.
-> ;
I googled but I cant solve my own
Any idea is appreciated

How i can import my database dump file in mysql in ubuntu server

i am executing query for importing sql dump in ubuntu
mysql -u username - p passsword databasenme < var/www/sql.sql;
error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u
There should not be any blank space between -p and the password.
mysql -u username -p<PASSWORD HERE> databasenme < var/www/sql.sql;
UPDATE:
I assumed you weren't logged in to mysql already. If you are, you should exit from mysql console and then retry.
You can import .sql file using :
mysql -u <user> -p<password> <dbname> < mysqlfile.sql
Note: There shouldn't space between -p and <password>
Reference: http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html
Time taken for importing huge files most importantly it takes more time is because default setting of mysql is "autocommit = true", you must set that off before importing your file.
First open MySQL:
mysql -u root -p
Then, You just need to do following :
mysql>use your_db
mysql>SET autocommit=0 ; source the_sql_file.sql ; COMMIT ;
You are logged in to mysql. press ctl+z to exit and try again.
don't write user's password on this line, type only flag -p , and in new line enter password:
$ mysql -u user -p database_name < your_file.sql
Enter password:
EDIT:
Check .sql file for syntax, maybe have a syntax error in the file.

mysql dump error

I'm having some difficulty with mysqldump. I locked my tables and ran the following command:
mysqldump -u user -p password databasename using my actual password and database name.
When I run this from mysql I get a 1064 error that says there is an issue with my syntax. I've also tried running the command from terminal (outside of mysql) and receive a 'command not found' error message. I'm not entirely sure how I should be doing this (the explanations I've found so far have been vague).
Thanks for the help.
The mysqldump is a program, it cannot be executed from the mysql console. Run it from the shell.
Have a look at the syntax reference.
--user=user_name, -u user_name
--password[=password], -p[password]
As you see there is no space between -p and password. So, your command line should be like this:
>shell mysqldump -u <user_name> -p<user_password> ...
or
>shell mysqldump --user=<user_name> --password=<user_password> ...
You are missing the target backup file name:
# [mysql dir]/bin/mysqldump -u username -p password --databases databasename > /tmp/databasename.sql
MySQL Commands
the correct syntax is
mysqldump -u [username] -p[password] [databasename] > [backupfile.sql]
you should add the > backupfile.sql
the other error is believe your system doesn't recognize the mysqldump path and you should go directly to bin folder from mysql installation.

Import mysql DB with XAMPP in command LINE

I have this command:
mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql
But I get the following error:
Error
unknow command '\U'
unknow command '\m'
unknow command '\D'
unknow command '\L'
For those using a Windows OS, I was able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
Also, I just wrote a more detailed answer to another question on MySQL imports, if this is what you're after.
Go to the xampp shell command line
and run
mysql -h localhost -u username databasename < dump.sql
You may also need to specify the host. From your statement, it looks like you run on Windows. Try this:
mysql -h localhost -u #myusername -p #mypasswd MYBASE
< c:/user/folderss/myscript.sql
Or
mysql -h localhost -u #myusername -p #mypasswd MYBASE
< "c:\user\folderss\myscript.sql"
mysql -h localhost -u username databasename < dump.sql
It works, try it.
If password is blank no need to add the -p args.
/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.sql
It works:
mysql -u root -p db_name < "C:\folder_name\db_name.sql"
C:\ is for example
Copy Database Dump File at (Windows PC)
D:\xampp\mysql\bin
mysql -h localhost -u root Databasename <#data11.sql
this command posted by Daniel works like charm
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
just put the db username and db name without those backets
**NOTE: Make sure your database file is reside inside the htdocs folder, else u'll get an Access denied error
No Doubt It does the trick:
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql
But some time you many find "MySql Server has Gone a way"
For that you need to change mysql/bin/my.ini max_allowed_packet = 64M to my.ini
I think the commands are OK, issue is with the spaces.
Please observe the spaces between -u and #myusername also between -p and #mypasswd.
mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql
Can also be written as:
mysql -u#myusername -p#mypasswd MYBASE < c:\user\folderss\myscript.sql
Also, you need not add -p and the time of command, if your password is blank, it will not ask you for the password.
If you have password to your database, it will ask for the password.
Thanks
The process is simple-
Move the database to the desired folder e.g. /xampp/mysql folder.
Open cmd and navigate to the above location
Use command to import the db - "mysql -u root -p dbpassword newDbName < dbtoimport.sql"
Check for the tables for verification.
In Windows, place the MySQL file (i.e. example.sql) in C:\xampp\mysql\bin.
Open the XAMPP Control Panel, and launch Shell:
cd c:\xampp\mysql\bin
mysql --default-character-set=utf8 -h localhost -u username databasename < example.sql
Note: Using --default-character-set=utf8 can help to prevent encoding issues with special characters if you intend on working with UTF-8.
Afterwards, remove the MySQL file from C:\xampp\mysql\bin.
Do your trouble shooting in controlled steps:
(1) Does the script looks ok?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
type ansi.sql
show databases
(2) Can you connect to your database (even without specified the host)?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
(3) Can you source the script? (Hoping for more/better error info)
mysql> source ansi.sql
+--------------------+
| Database |
+--------------------+
| information_schema |
| ... |
| test |
+--------------------+
7 rows in set (0.01 sec)
mysql> quit
Bye
(4) Why does it (still not) work?
DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql < ansi.sql
Enter password: ********
Database
information_schema
...
test
I suspected that the encoding of the script could be the culprit, but I got syntax errors for UTF8 or UTF16 encoded files:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '´╗┐
show databases' at line 1
This could be a version thing; so I think you should make sure of the encoding of your script.
I think the OP's problem was not escaping the slashes.
on windows a path like: "c:\user\folderss\myscript.sql" should in the command line be written like either:
c:\\\user\\\folders\\\myscript.sql
or:
c:/user/folders/myscript.sql
therefore "\u" from "c:\user" was interpreted as a command.
see: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html for more info
here is my try to import database from cmd in xampp server
the correct command for me is this you can change it with your requirements.and i also attached Errors that i face first time importing db from command line.you can see last command that i use and i paste it here also its working fro me.
mysql -h localhost -u root ovxsolut_windhs < C:\Users\eee\Downloads\ovxsolut_windhs.sql
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/filename.sql
mysql -u root -p dbname< "C:\Users\sdkca\Desktop\mydb.sql"
mysql -h localhost -u username -p databasename < dump.sql