I’m in the MySQL command line client mysql monitor, trying to do a mysqldump command on the database with which I have an open connection. This is the command I’m using at the mysql> prompt:
mysqldump -u username -p password databasename > dumpfilename.sql\g.
I assume that the file dumpfilename.sql will be created when the dump is successful. I have tried it with and without pw, un, end-of-line semicolon, etc. I am getting
error 1064 syntax error
over and over again. What am I doing wrong?
mysqldump is a program, not a MySQL command. Exit the mysql client and enter the mysqldump -u username -p password databasename > dumpfilename.sql command at the shell prompt and it will work
Related
i have a dump file on drive z (network drive)
im opening the psql from PgAdmin4
this is the command that im writeing:
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
and this is the error that im getting:
Invalid command \DB_BU. Try \? for help.
when im doing this:
psql -U postgres -d postgres -f i\ Z:\DB_BU\md_20220729.sql
Invalid command \DB_BU. Try ? for help.
and when im doing this:
psql -U postgres -d postgres -f "Z:\DB_BU\md_20220729.sql"
im not getting any error but also its not restoring the file. how can i restor the file?
You're trying to call psql from within psql or PGAdmin. Since
psql is a standalone program, not an SQL command you can run in PGAdmin SQL window or psql's own, internal meta-command you're getting the error
Invalid command \DB_BU. Try \? for help
indicating that there was an attempt to interpret your entire command as a SQL query or an internal command and that this attempt failed.
You can open "psql tool" from within PGAdmin but your command won't work there either because it's trying to call psql itself, with some command-line options, which you cannot do when you're already inside an interactive psql session. The command
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
can be used outside psql and PGAdmin, in your terminal, like zsh on Mac, sh/bash on Linux, cmd or PowerShell on Windows, where psql is installed and visible, along with your network path.
If you're able to open the psql tool window in PGAdmin, you can instead try and use an internal psql \i meta-command which is basically the same thing as the -f command-line option, but meant for use inside the psql session:
\i "Z:\DB_BU\md_20220729.sql"
On Windows 10, using psql with PostgreSQL 14 installed, I'm trying to restore a dump that is my_dump.sql.
I'm on Bash terminal currently.
I'm connected to psql server and I created a new database new_db, then a new superuser tobe.
Then I tried the command psql -d new_db < my_dump.sql but I'm getting the error stdin is not a tty
I tried the solution psql -U tobe -d new_db -f my_dump.sql from "stdin is not a tty" when populating Postgres database
because they mention the error but now I get a new error:
ERROR: syntax error at or near "ÿþ" LIGNE 1 : ÿþ
Are the two errors connected? Maybe the second error is only related to the command syntax. I'm not sure if I'm in the right direction.
Try
psql.exe -U tobe -d new_db -f my_dump.sql
I am trying to work out a way to perform a PostgreSQL pg_dump of a single DB via RHEL v6.10 command line. Now the system I am working on is that you have to shell into Bash 4.1 first before you get to PSQL. Now I can access the actual PSQL db using the following syntax from the command line which works fine:
'''sudo -u postgres -H --psql -pxxxxx -d db_name'''
If I enter the following syntax from the RHEL command line:
'''sudo su postgres'''
I end up in the bash-4.1 shell. When executing the following command from within the shell: bash-4.1$ pg_dump db_name > /tmp/my_database.sql
I am presented with the following error:
pg_dump: [archiver (db)] connection to database "db_name" failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I am expecting the db to be exported to /tmp/my_database.sql file. I have tried various combinations of commands from both RHEL and bash command lines but cannot achieve the desired outcome. Your assistance would be greatly appreciated, thank you.
Try this:
Connect as 'postgres' user
sudo -i -u postgres
Then run pg_dump, e.g.
pg_dump --blobs --file /your/backup/file/path/backupfilename.pgsql --dbname your_db_name
After that, you will find your backup file in /your/backup/file/path/backupfilename.pgsql
You can add many other options in pg_dump, See PostgreSQL Documentation
I have made required entries in .pgpass file with file permission set to 0600.
I am able to connect to db form shell command line without giving the password.
But when I run a shell script which internally queries postgres, it asks to enter password.
I am not able to figure out what could be wrong.
Here is a sample shell script:
#!/bin/bash
source $1
psql -h $DBHOST -d $DBNAME -U $DBUSER << EOF
select * from students limit 10;
EOF
All values for DBHOST, DBNAME and DBUSER are coming fine.
Nevermind.
I made a stupid mistake. I had edited config file on windows. So it had added crlf at the end of every line. So even though it was not visible it was being used when connecting to postgres.
So in command line
this worked.
psql -h 192.168.1.45 -d somedbname -U $somedbuse
But this did not. (after sourcing config file)
psql -h $DBHOST -d $DBNAME -U $DBUSER
I am trying to restore the postgres sql data from a file . I am trying to do so but it is not importing .
Here is the command which i am using:
postgres-# psql -hlocalhost -p5432 -u postgres -d test -f C:/wamp/www/test/database_backups/backup004.sql
Please help me what I am doing wrong .
I am using windows and the above command does not throws any error but it does not import data.
Regards
Surjan
The only immediate thing I can see there is the capitilsation of -u for username (should be -U).
Correction: You're typing the command line into the psql shell.
You should exit to the CMD.EXE shell, and try the command there. With the correct capitalisation of -U, by the way.
OR, use this to replay the script into that psql shell:
\i C:/wamp/www/test/database_backups/backup004.sql
The forward slashes don't cause a problem on my Windows machine.