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.
Related
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/
I want to write a cron job to INSERT INTO 6 tables. I know that :
The tables will always exist and will be empty, awaiting records
I will have 6 .sql dump files On the server which will be ready to be imported.
The format of the files are exactly as created by the phpMyAdmin export tool
i.e. all already have a single INSERT INTO tablename line and multiple parenthisised value lines.
All have foreign-key constraints set to off before the insert statement and toggled on again after the inserts.
i wanted to do all from within PHP but on a shared hosting the exec() func is disabled and so is the FILES priviledge so my options are dwindling.
I'm looking for a way to do the above from cPanel cron or SSH tools in cPanel. CRON would be my first choice since i'm unfamiliar with SSH.
Do i run this line 6 times (for each file) or can i consolidate it into one cron or ssh command? p.s. also do i use absolute or relative paths to the .sql dump files
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h ... etc ...
thanks
You can create a task.sh file located at /home/youruser/ and inside you can put the following:
#!/bin/bash
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-4.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-5.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-6.sql'
Then, to execute this cron, from cPanel, you create a Cronjob, configure the time as needed and the command it should execute is:
/home/youruser/task.sh
And you are done.
I hope it works for you
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.
What I have done:
mysql -u root -p -h localhost gx < gxe.sql
Result:
[root#jony html]# mysql -u root -p -h localhost gx < gxe.sql
Enter password:
[root#jony html]#
It actually doesn't do anything.. I tried refreshing my SQL client (Heidi SQL), and still nothing?.
What have I done wrong? Thanks!
OS: CentOS 6 - Linux
mysql and mysqldump have slightly different syntax
mysql needs -D parameter to set the database.
So try
mysql -u root -p -h localhost -D gx < gxe.sql