dumping DB in mysql - mysql

when I run below statement, mysql is complaining having error.
mysqldump --triggers --routines -u root -p mydb > mydb_20120924.dmp;
mysql version: 5.1.34
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 'mysqldump --triggers --routines -u root -p mydb > mydb_20120924.dmp' at line 1

It looks like you are trying to run the mysqldump command from inside the mysql command line interpreter.
Does the prompt for the mysqldump command say 'mysql> '? Then you are running the mysql command line interpreter. It should be used - indeed, it can only be used - for running mysql commands.
mysqldump is a separate command and must be run from the shell.
Quit mysql by typing "exit" - you will see a shell prompt. Then the mysqldump command will work.

If you have a database called "mydb" this should work. You could try using --database specifically:
mysqldump --triggers --routines -u root -p --database mydb >
mydb_20120924.dmp;

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

How to backup stored procedure backup from Google Cloud SQL?

I want to create/export only the stored procedures from my Google Cloud SQL DB. I tried several commands on my phpmyadmin(installed on Google App Engine) console but I am consistently facing the error mentioned below.
List of commands I've tried:
1. mysqldump --routines=true -u root sarda_yogi_mobile > my_database.sql
2. mysqldump --databases database_name [-h instance-ip -u username -p password] \ --hex-blob --default-character-set=utf8 > database_file.sql
3. mysqldump --databases database_name [-h instance-ip -u username -p password] --default-character-set=utf8 > database_file.sql
4. mysqldump --host="127.0.0.1" --user="root" --password="" --routines --triggers --events dbname > my_file.sql
Error Message:
#1064 - 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 'mysqldump --routines=true -u root db_name > my_database.sql' at line 1
Can anyone point me in the right direction? Thank You :)
As #Vadim said, you're attempting command-line statements at a SQL shell, which (as you've seen) doesn't work.
To perform a stored procedure export from within phpMyAdmin, go to the "Routines" tab of your database and click "Export" for the routine you wish to export. You could instead use the checkboxes to select several to export at once, if you prefer.
Those are commands you need to run on a command line, not via the phpMyAdmin shell.
If you want to perform an export from phpMyAdmin, there are some guides available on the web, e.g. http://www.inmotionhosting.com/support/website/phpmyadmin/export-database-using-phpmyadmin

mysqldump error in exporting a table from a database

Can anyone please let me know why am I getting this 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 'mysqldump -p --user=root database_name utilities > utilities.sql'
on this mysqldump -p --user=root database_name utilities > utilities.sql;
I tried keeping the database name, table name in backticks. Nothing seems to work.
mysqldump should be run from a normal command prompt/shell instead of the mysql command, not at the mysql prompt inside it.
ubuntu-vm:~$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.31-0ubuntu0.13.04.1 (Ubuntu)
mysql> exit
Bye
ubuntu-vm:~$ mysqldump -help
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
ic#ubuntu-vm:~$

mysql dump, windows, seperate files for each DB, all databases option

Does anybody have an example on how to dump all databases uses mysql dump? And possible all a new file for each DB?
I'm using the follow command:
mysqldump -u root -p pw --all-databases > backup.sql;
It's returning with "You have an error in your SQL sytax";
Thanks!
There is an error in your command, it should be no space after -p,
like
mysqldump -u root -ppw --all-databases > backup.sql;
I not sure how many database you have, usually you can do this :-
mysqldump -u root -ppw db_a > db_a.sql;
mysqldump -u root -ppw db_b > db_b.sql;
...
... for all the databases

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.