Error in Mysqldump command - sql

I have a data base named "mig". it has 10 tables. now i want to create a same database in another system so I am using mysqldump command but it shows error.
I entered command as follows :
mysqldump -u root -p root mig >file.sql;
This is the error i got :
ERROR 1064 (42000): 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
dump -u root -p root mig >file.sql' at line 1
I am getting the same error when I use ,
mysqldump -u root -proot mig >file.sql;
How can i fix this ?

Simply try-
mysqldump -u root mig> file.sql
Edit
mysqldump is not a MySQL command, it is a command line utility. You must call it from your shell command line. I hope you are not calling this from MySQL prompt.

When providing password on the command line you should leave no space after -p.
It should look smth like:
mysqldump -u root -proot mig >file.sql;

You can use some tools like MySQL Workbench or SQLyog to import the dump file.
Free version: https://code.google.com/p/sqlyog/wiki/Downloads

When you execute mysqldump from command line, you must have mysql_home/bin directory in your classpath variable or command-line must be pointing to it.
try using
mysqldump -u root -proot mig >(abs_path)/file.sql;

This works for me on my local. Open Terminal and execute the following code (Make sure your are NOT on the MySQL prompt):
mysqldump -uroot -p mig > file.sql
It will ask you to input the password on the next line, for security the password won't be shown.
If you get Access Denied, means the mysql credentials are wrong (or the user you use don't have the right permissions to generate a dump), so make sure you have a valid username and password. I hope it helps.

mysqldump will not run from mysql cli, you will have to run it from windows command prompt:
mysqldump -u username -p database_name > output_file_name.sql;
If you are getting error on running above command 'mysqldump is not recognized as an internal or external command' then navigate to < MySQL Installation Directory/bin/ > and then run the command.

i have the same problem, my situation was i connect from client in local computer to server in SQL instance of Google. Since i read Sahil Mittal said this is comman utilty, i just put in terminal the same command adding -h parameter.
mysqldump -h ip.del.host -u root -p database_name > database_desired_name.sql

Related

Errors ("invalid command") when opening a .sql file

I am trying to open a random .sql file off the internet using the following command:
psql -h localhost -d database_name -U postgres < file_name.sql
But when I run this command I just get errors like the following:
invalid command 's
invalid command 's
invalid command 'll
invalid command 'Moving
invalid command 's
invalid command "frequently
It just continuously prints out these invalid command error messages. I thought it might be an encoding problem but I confirmed the file is UTF-8 encoded.
Any suggestions on how I can open this file
To expand and clarify on a_horse_with_no_name's comment - the psql command you are running should be run directly in your shell, not inside pgadmin4.
youruser#yourmachine:~$ psql -h localhost -d database_name -U postgres < file_name.sql
That command should load the contents of file_name.sql in to database_name. Once it's complete, you can use pgadmin4 as normal to interact with the database.
One possibility is that the file contains tabulator keys, which are expanded if you read redirect standard input to the SQL script.
Try using the -f option:
psql -h localhost -d database_name -U postgres -f file_name.sql
Apparently the .sql file was generated through a MySQL dump. I thought it would not matter whether I used PostgreSQL or MySQL but it did. Once I installed MySQL my problem got resolved and I now have a Database ready :)

Cannot execute script: Insufficient memory to continue the execution of the program

I have a 123MB sql file which I need to execute in my local PC. But I am getting
Cannot execute script: Insufficient memory to continue the execution of the program
How to solve this issue?
use the command-line tool SQLCMD which is much leaner on memory. It is as simple as:
SQLCMD -d <database-name> -i filename.sql
You need valid credentials to access your SQL Server instance or even to access a database
Taken from here.
It might help you! Please see below steps.
sqlcmd -S server-name -d database-name -i script.sql
Open cmd.exe as Administrator.
Create Documents directory.
Put your SQL Script file(script.sql) in the documents folder.
Type query with sqlcmd, server-name, database-name and script-file-name as like above highlighted query or below command line screen.
For Windows Authentication use this sql cmd
SQLCMD -S TestSQLServer\SQLEXPRESS -d AdventureWorks2018 -i "d:\document\sql document\script.sql"
Note: If there is any space in the sql file path then use " (Quotation marks) "
For SQL Server Authentication use this sql cmd
SQLCMD -S TestSQLServer\SQLEXPRESS -U sa -P sasa -d AdventureWorks2018 -i "d:\document\sql document\script.sql"
-S TestSQLServer\SQLEXPRESS: Here specify SQL Server Name
-U sa: Username (in case of SQL Server Authentication)
-P sasa: Password (in case of SQL Server Authentication)
-d AdventureWorks2018: Database Name come here
-i "d:\document\sql document\script.sql": File Path of SQLFile
You can also simply increase the Minimum memory per query value in server properties. To edit this setting, right click on server name and select Properties > Memory tab.
I encountered this error trying to execute a 30MB SQL script in SSMS 2012. After increasing the value from 1024MB to 2048MB I was able to run the script.
(This is the same answer I provided here)
My database was larger than 500mb, I then used the following
C:\Windows>sqlcmd -S SERVERNAME -U USERNAME -P PASSWORD -d DATABASE -i C:\FILE.sql
It loaded everything including SP's
*NB: Run the cmd as Administrator
If I understand your problem correctly, you are trying to restore (transact sql) xyz.sql - database + schema. You can try this command which worked for me:
SQLCMD -U sa -i xyz.sql
Try this step,
1)Open PowerShell
2)Write this command:
sqlcmd -S PCNAME\SQLEXPRESS -U user -P password -d databanse_name -i C:\script.sql
3)Press Return
:-)
Below script works perfectly:
sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql -x
Symptoms:
When executing a recovery script with sqlcmd utility, the ‘Sqlcmd: Error: Syntax error at line XYZ near command ‘X’ in file ‘file_name.sql’.’ error is encountered.
Cause:
This is a sqlcmd utility limitation. If the SQL script contains dollar sign ($) in any form, the utility is unable to properly execute the script, since it is substituting all variables automatically by default.
Resolution:
In order to execute script that has a dollar ($) sign in any form, it is necessary to add “-x” parameter to the command line.
e.g.
Original:
sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql
Fixed:
sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql -x
Sometimes, due to the heavy size of the script and data, we encounter this type of error. Server needs sufficient memory to execute and give the result. We can simply increase the memory size, per query.
You just need to go to the sql server properties > Memory tab (left side)> Now set the maximum memory limit you want to add.
Also, there is an option at the top, "Results to text", which consume less memory as compare to option "Results to grid", we can also go for Result to Text for less memory execution.
sqlcmd -S mamxxxxxmu\sqlserverr -U sa -P x1123 -d QLDB -i D:\qldbscript.sql
Open command prompt in run as administrator
enter above command
"mamxxxxxmu" is computer name
"sqlserverr" is server name
"sa" is username of server
"x1123" is password of server
"QLDB" is database name
"D:\qldbscript.sql" is sql script file to execute in database
If you need to connect to LocalDB during development, you can use:
sqlcmd -S "(localdb)\MSSQLLocalDB" -d dbname -i file.sql
As in most answers given here use the command-line tool. In my case the script already has database creation code. If your script contains CREATE DATABASE command, for example
USE [master]
GO
CREATE DATABASE [your-database-name]
Then do not use the -d your-database-name, instead use the following command.
For Windows Authentication use the command
sqlcmd -S ServerName\InstanceName -i "script.sql" -x
For SQL Server Authentication use the command
sqlcmd -S ServerName\InstanceName -U usename -P password -i "script.sql" -x

How do I open an sql database that I downloaded using the terminal?

How can I import a database with MySQL from terminal?
the syntax from this thread
mysql -u username -ppassword databasename < filename.sql
my input for the file (lahman591) i placed on my root for simplicity sake
mysql> mysql -u root -p lahman591 <c:\lahman591.sql
i get an Error:
ERROR 1064 (42000) You have an error in your sql syntax.
You need to do it from your normal shell (the command is calling the mysql bin), not mysql shell.

Extracting an existing schema in MySQL, getting an unknown error, need help

Trying to dump the schema for an existing MySQL database. Appears the best way is this command:
CMD:
mysqldump -d -u root -pPASSWORD_REMOVED MyOffice
NOTE: There is no space between "-p" and "PASSWORD_REMOVED", and PASSWORD_REMOVED equals my password; which is working. MyOffice is the database name.
OUTPUT:
mysql> use MyOffice;
Database changed
mysql> mysqldump -d -u root -pPASSWORD_REMOVED MyOffice
-> ;
ERROR 1064 (42000): 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
dump -d -u root -pmysql123 MyOffice' at line 1
GOOGLE:
This is what I've Googled so far, search-1, search-2... no luck
You are executing mysqldump from the mysql prompt which is not correct! This is clear from your output.
You have to execute the mysqldump command from the system command prompt (shell), not from mysql prompt!

Importing .sql file on windows to postgresql

I have a .sql file that was created by postgresql a while back. I now want to import this file onto a windows machine running postgresql.
How do I do this. The file is about 1.5gb.
You should use psql command line tool:
psql -h hostname -p port_number -U username -f your_file.sql databasename
click on the SQL Shell and log into the database and use import
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (9.2.4)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=# \i c:/data/data01.sql
start you psql command tool, it will give you dialog like the following
Server [localhost]:
Database [postgres]:
Port [5432]:yourport
Username [postgres]:
Password for user postgres:**********
then connect to your database
postgres=# \c yourdatabase;
then import the file
yourdatabase=# \i c:/path/path/data/data01.sql
note the / for directory separator & no spaces in file path
This also works for me:
psql dbname username < file.sql
command prompt
open your cmd window and type the following (make sure the path of postgres is correct)
."C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h 127.0.0.1 -p 5432 -U postgres -d dbname <./query.sql
psql -U <dbusername>
if the prompt makes you enter password, do that.
\c <yourdatabasename>
\i 'thepathusing/delimiter.sql'
Two points you need to watch out that
Use / as writing path of the file instead of \.
Use single quote
symbol ' instead of ".
If you're doing it with a URI connection string make sure the arguments are before the URI, Powershell examples:
Works on windows:
.\psql -f TestFile.sql $connString
.\psql -c 'SELECT Version();' $connString
Won't work on windows (URI connection before arguments):
.\psql $connString -c 'SELECT Version();'