I was trying to migrate my WordPress blog from the server and somehow I corrupted my sql database.
I have typed these commands into my Centos VPS:
mysqldump -u root -QqeR --add-drop-table --databases blogsql -> blog.sql
mysql -u root blogsql -> blog.sql
mysql -u root blogsql > blog.sql
mysql -u root -p blogsql > blog.sql
mysql -u root -p blogsql > blog.sql
mysql -u root -p blogsql > blog.sql
mysql -u root -p blogsql > blog.sql
mysql -u root blogsql > blog.sql
Your using the wrong operator.
> redirects output which is what you want for the dump
< is what you want to restore
so
mysql -u root -p blogsql < blog.sql should import it
also typo in the first line
mysqldump -u root -QqeR --add-drop-table --databases blogsql -> blog.sql
should be
mysqldump -u root -QqeR --add-drop-table --databases blogsql > blog.sql
Thank you guys for the help, the database was not corrupted, just iptables was blocking my 80port so I thought I have overwitten the database, but it had no issues.
anyways thank you for the help guys!
Related
I copied an sql text file into /var/lib/mysql-files directory but the command:
>mysql -u root -p < /var/lib/mysql-files/test.sql
but I get the error:
bash: /var/lib/mysql-files/test.sql: Permission denied
The file has permissions set to 0744.
You can use MySQL dump for this.
For creating a backup use:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
For restoring a version use:
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
For a number of reasons describe here:
STRANGE Situation -> Mysql ERROR 2002 (HY000)
I cannot use mysqldump. Is there another program or way to dump dbs through the mysql console? The only way I can get into the console is running
mysql -h 127.0.0.1 -P 3306 -u root -p
(due to problems stated above - or if I re-install mysql, which could be risky)
Hope someone help us save our data!
for the future, the SOLUTION:
mysql -h 127.0.0.1 -P 3306 -u root -p -e "show databases;" | tr -d "| "
mysql -h 127.0.0.1 -P 3306 -u root -p -e "show databases;" \
| tr -d "| " \
| egrep -v "(Database|mysql|information_schema)"
for db in \
mysql -h 127.0.0.1 -P 3306 -u root -p -e "show databases;" \
| tr -d "| " \
| egrep -v "(Database|mysql|information_schema)"; \
do mysqldump -h 127.0.0.1 -P 3306 -u root -p --opt --routines --databases $db "$db.sql"; done
I received this error in one of the databasese, but it hasn't affected my production ones, so Im cool with it.
mysqldump: Got error: 1142: SELECT,LOCK TABL command denied to user 'root'#'localhost' for table 'cond_instances' when using LOCK TABLES
Credits to:
http://vitobotta.com/smarter-faster-backups-restores-mysql-databases-with-mysqldump/
Using mysqldump on windows(2003-server - MariaDB) produces following error:
mysqldump: Got error: 1045: "Access denied for user 'ODBC'#'localhost' (using password: YES)" when trying to connect
Commands I used:
mysqldump --user=root --password=password -h127.0.0.1 --port=3306 database > backup.sql
mysqldump -uroot -ppassword database > backup.sql
mysqldump -uroot -p(enter password on promt) database > backup.sql
mysqldump -u root -p password database > backup.sql
mysqldump -u root -ppassword database > backup.sql
Etc, anything I used, same error popped up.
Looks like some default-hardcoded user/password is used.
I can connect to mysql -uroot -p just fine.
Internets have seen this error before, but I have not seen proper solution to this or I am oblivios to something.
Any insight would be amazing.
Thanks.
Double check your - char in your commands. Sometimes copy&paste produces a different hyphen char.
Your command below should work:
mysqldump -u root -ppassword database > backup.sql
mysqldump -u root -p Databasename > backup.sql
How to set in this command password? I need run this command in Python script.
At this time, asking me for a password.
mysqldump -u root -pPassword Databasename > backup.sql
Read this for some basic security info.
Assuming you're on Unix...
env MYSQL_PWD=<password> mysqldump -u root -p Databasename > backup.sql
According to the mysql docs.
I am trying to replicate my mysql database using the master slave replication. On the slave machine, when i try to run this query, i get stuck.
mysqldump -h 10.124.2.34 bank --password='' --user='root' | mysql bank --password='' --user='root'
Any idea what I am doing wrong?
Try this :
Total DB dump :
mysqldump -uroot -h -p pwd -P db_name | mysql -uroot -p pwd -P db_name
Only Table copy
mysqldump -uroot -h -p pwd -P db_name | mysql -uroot -p pwd -P db_name
It's working for me.