How to backup and restore in MySQL 5.2? - mysql

This is the command I used:
mysql> mysql -u root -p -h HOST sample < mysqldump.sql;
But I encountered an error as follows:
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 -u root -p -h HOST sample < mysqldump.sql' at line 1
Hope you can help me out?

That's the command you should give in the command line, not in MySQL itself.

Open mysql terminal or konsole and then go to the directory where mysqldump.sql file is present. try:
shell> cd /file_path/;
shell> ls -al mysqldump.sql;
It should display your file. Also you dont need to specify HOST if you are logged on to the same server.
shell> mysql -u root -p sample < mysqldump.sql;

from client you can run \. mysqldump.sql but i think first variant is preferable.

Related

Make a backup of a MariaDB database

I want to make a backup of a db in mariaDB, I've used the following statements but any work.
mysqldump -u root -p -databases messages > dbdescargada.sql
mysqldump -u root -p messages > dbdescargada.sql
mysqldump -u root messages > clients.sql
mysqldump --user='root' --add-locks messages messages > copia.sql
mysqldump --user='root' --add-locks messages messages > copia.sql
But all showed the same error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'statement' at line 1
I really need to do this backup cause I need to make important changes to the tables structures,
I'm using Xampp for Linux, Ubuntu 20.04
I know I can do it from localhost/phpmyadmin but I need also a code option
You have 2 problems:
1) You are running it from mysql CLI. mysqldump is a shell command, not a mysql command.
2) Lose the - in -> redirect to file - there is no minus before >
The parameter is --databases
Your images suggests that you run the shell command in the mysqlshell that is wrong, yoz must run it in a normal command window bash msdods...
Please check the parameters
mysqldump -u root -p --databases messages > dbdescargada.sql

Issue to clone mysql DB

I try to clone my_db to my_db_clone. I followd this post and this but I get always
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
I tried thise but none worked, I get always that error :
mysqldump -u my_user -p my_db | mysql -u backup -pmy_password my_db_clone
mysqldump my_db | mysql my_db_clone;
mysqldump my_db -u my_user -pMy_passwprd > dumpdb.sql;
The mysqldump utility runs in the shell. How are you invoking it? Based on your error message, it appears that you might be trying to run it in the mysql client.
Try it in the shell instead.

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.

How to properly dump mysql database via mysqldump?

Does mysqldump utility requires any seperate client ??
I'm using MYSQL5.5 command line client for windows..
I'm writing query
mysqldump -u root -p pwd** my_db > mydb.sql
I'm getting the error
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 t
The problem is that you're running the command in the MySQL command line client. Run it from a shell instead, not inside of the client.
In other words, open a normal shell (cmd.exe if using Windows), and run: (your path to mysqldump.exe will no doubt differ)
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump -u root -ppwd** my_db > mydb.sql
Do not open up the MySQL command line client and run that command inside of there. That client is for executing SQL; the mysqldump.exe program is completely separate and runs on its own.
> not <
You're dumping the file mysql.sql INTO mysqldump, not out of it
mysqldump -u root -p pwd** my_db > mydb.sql

mysql (5.1) command line interface and my madness

Got two little problems with this interface. The worse one is that I have a file with a blank line (i have removed the SQL to demonstrate!). Tried to use mysql but get this
C:\Users\edheal\Desktop>mysql -e "blank.sql" -h localhost -u test -p
Enter password: *
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the ma
nual that corresponds to your MySQL server version for the right syntax to use n
ear 'blank.sql' at line 1
C:\Users\edheal\Desktop>cat -v "blank.sql"
^M
C:\Users\edheal\Desktop>
What could possibly be the problem? It is just a blank line!
The second - just me being lazy during development. Is it possible to not have a password on the account? Seems that the minimum is one character.
A blank line is not a valid SQL statement therefore it's a syntax error.
Try to use
mysql -h localhost -u test -pYourPasword < "blank.sql"
One some standard installations, the root user does not have any password. But it is not possible to set an existing password to "empty".
The -e or the --execute option expects you to have the SQL command following it:
mysql -e "select ....." -h localhost -u test -p
If you want to execute the commands listed in a file say test.sql you can do:
mysql -h localhost -u test -p < test.sql