我想知道在没有提示密码的情况下执行数据库mysqldump的命令。
原因: 我想运行一个cron作业,每天对数据库进行一次mysqldump。因此,当提示时,我将无法插入密码。
我怎么解决这个问题呢?
我想知道在没有提示密码的情况下执行数据库mysqldump的命令。
原因: 我想运行一个cron作业,每天对数据库进行一次mysqldump。因此,当提示时,我将无法插入密码。
我怎么解决这个问题呢?
当前回答
检查你的密码!
Took me a while to notice that I was not using the correct user name and password in ~/.my.cnf Check the user/pass basics before adding in extra options to crontab backup entries If specifying --defaults-extra-file in mysqldump then this has to be the first option A cron job works fine with .my.cnf in the home folder so there is no need to specify --defaults-extra-file If using mysqlpump (not mysqldump) amend .my.cnf accordingly The ~/.my.cnf needs permissions set so only the owner has read/write access with: chmod 600 ~/.my.cnf
下面是一个例子。my.cnf:
[mysql]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
[mysqldump]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
[mysqlpump]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
localhost不需要主机和端口条目 如果您在linux中的用户名与备份时使用的用户名相同,则不需要使用user
另一个提示,当你为mysqldump执行cronjob条目时,你可以用ionice -c将它设置为低优先级任务。结合InnoDB的——single-transaction选项,你可以运行备份,不会锁定表或锁定其他地方可能需要的资源。
其他回答
对我来说,使用MariaDB我必须这样做:添加文件~/.my.cnf,并通过执行chmod 600 ~/.my.cnf更改权限。然后将您的凭据添加到文件中。神奇的是,我错过了密码需要在客户端块下(参考:docs),就像这样:
[client]
password = "my_password"
[mysqldump]
user = root
host = localhost
如果你碰巧来这里寻找如何用MariaDB做mysqldump。将密码放在[client]块下,然后将用户放在[mysqldump]块下。
检查你的密码!
Took me a while to notice that I was not using the correct user name and password in ~/.my.cnf Check the user/pass basics before adding in extra options to crontab backup entries If specifying --defaults-extra-file in mysqldump then this has to be the first option A cron job works fine with .my.cnf in the home folder so there is no need to specify --defaults-extra-file If using mysqlpump (not mysqldump) amend .my.cnf accordingly The ~/.my.cnf needs permissions set so only the owner has read/write access with: chmod 600 ~/.my.cnf
下面是一个例子。my.cnf:
[mysql]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
[mysqldump]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
[mysqlpump]
host = localhost
port = 3306
user = BACKUP_USER
password = CORRECTBATTERYHORSESTAPLE
localhost不需要主机和端口条目 如果您在linux中的用户名与备份时使用的用户名相同,则不需要使用user
另一个提示,当你为mysqldump执行cronjob条目时,你可以用ionice -c将它设置为低优先级任务。结合InnoDB的——single-transaction选项,你可以运行备份,不会锁定表或锁定其他地方可能需要的资源。
——password="" 在5.1.51上运行对我有用
mysqldump -h localhost -u <user> --password="<password>"
我用不同的方式,使用Plink(Putty命令行)连接到remotehost,然后下面的命令是在远程服务器上运行的Plink文件中,然后我使用RSYNC从windows获取它并备份到onprem NAS。
sudo mysqldump -u root --all-databases --events --routines --single-transaction > dump.sql
我在远程主机上设置了密钥,并使用PowerShell,通过任务调度器每周运行一次。
是的,这很简单....只需要一个神奇的命令行
mysqldump --user='myusername' --password='mypassword' -h MyUrlOrIPAddress databasename > myfile.sql
完成:)