Hi i have to move mysql database to another server ,
嗨,我必须将mysql数据库移动到另一台服务器,
It's nearly 5 gb
它接近5 GB
i can have root access at both servers?
我可以在两台服务器上拥有root权限吗?
3 个解决方案
#1
22
Usually you run mysqldump to create a database copy and backups as follows:
通常运行mysqldump来创建数据库副本和备份,如下所示:
$ mysqldump -u user -p db-name > db-name.out
Copy db-name.out file using sftp/ssh to remote MySQL server:
使用sftp / ssh将db-name.out文件复制到远程MySQL服务器:
$ scp db-name.out user@remote.box.com:/backup
Restore database at remote server (login over ssh):
在远程服务器上恢复数据库(通过ssh登录):
$ mysql -u user -p db-name < db-name.out
OR
$ mysql -u user -p 'password' db-name < db-name.out
How do I copy a MySQL database from one computer/server to another?
如何将MySQL数据库从一台计算机/服务器复制到另一台?
Short answer is you can copy database from one computer/server to another using ssh or mysql client.
简而言之,您可以使用ssh或mysql客户端将数据库从一台计算机/服务器复制到另一台计算机/服
You can run all the above 3 commands in one pass using mysqldump and mysql commands (insecure method, use only if you are using VPN or trust your network):
您可以使用mysqldump和mysql命令在一次传递中运行以上所有3个命令(不安全的方法,仅在您使用VPN或信任您的网络时使用):
$ mysqldump db-name | mysql -h remote.box.com db-name
Use ssh if you don't have direct access to remote mysql server (secure method):
如果您无法直接访问远程mysql服务器(安全方法),请使用ssh:
$ mysqldump db-name | ssh user@remote.box.com mysql db-name
OR
$ mysqldump -u username -p'password' db-name | ssh user@remote.box.com mysql -u username -p'password db-name
You can just copy table called foo to remote database (and remote mysql server remote.box.com) called bar using same syntax:
您可以使用相同的语法将名为foo的表复制到名为bar的远程数据库(和远程mysql服务器remote.box.com):
$ mysqldump db-name foo | ssh user@remote.box.com mysql bar
OR
$ mysqldump -u user -p'password' db-name foo | ssh user@remote.box.com mysql -u user -p'password' db-name foo
Almost all commands can be run using pipes under UNIX/Linux oses.
几乎所有命令都可以在UNIX / Linux下使用管道运行。
More from Reference
更多来自参考
Regards,
#2
14
If you have Root, you might find it quicker to avoid mysqldump
. You can create the DB on the destination server, and copy the database files directly. Assuming user
has access to the destination server's mysql directory:
如果你有Root,你可能会发现避免使用mysqldump更快。您可以在目标服务器上创建数据库,并直接复制数据库文件。假设用户可以访问目标服务器的mysql目录:
[root@server-A]# /etc/init.d/mysqld stop
[root@server-A]# cd /var/lib/mysql/[databasename]
[root@server-A]# scp * user@otherhost:/var/lib/mysql/[databasename]
[root@server-A]# /etc/init.d/mysqld start
Important things here are: Stop mysqld on both servers before copying DB files, make sure the file ownership and permissions are correct on the destination before starting mysqld on the destination server.
这里重要的是:在复制DB文件之前在两台服务器上停止mysqld,确保在目标服务器上启动mysqld之前,目标上的文件所有权和权限是正确的。
[root@server-B]# chown mysql:mysql /var/lib/mysql/[databasename]/*
[root@server-B]# chmod 660 /var/lib/mysql/[databasename]/*
[root@server-B]# /etc/init.d/mysqld start
With time being your priority here, the use of compression will depend on whether the time lost waiting for compression/decompression (with something like gzip
) will be greater than the time wasted transmitting uncompressed data; that is, the speed of your connection.
由于时间是你的优先考虑,压缩的使用取决于等待压缩/解压缩(用gzip之类的东西)的时间是否大于传输未压缩数据所浪费的时间;也就是你的连接速度。
#3
2
For an automated way to backup your MySQL database:
对于备份MySQL数据库的自动方式:
The prerequisites to doing any form of backup is to find the ideal time of day to complete the task without hindering performance of running systems or interfere with users. On that note, the size of the database must be taken into consideration along with the I/O speed of the drives - this becomes exponentially more important as the database grows ( another factor that comes to mind is the number of drives, as having an alternate drive where the database is not stored would increase the speed due to the heads not performing both reads and writes.) For the sake of keeping this readable I'm going to assume the database is of a manageable size ( 100MB ) and the work environment is a 9am-5pm job with no real stress or other running systems on off hours.
执行任何形式的备份的先决条件是找到完成任务的理想时间,而不会妨碍运行系统的性能或干扰用户。在这方面,必须考虑数据库的大小以及驱动器的I / O速度 - 随着数据库的增长,这变得越来越重要(想到的另一个因素是驱动器的数量,因为有一个未存储数据库的备用驱动器会因为磁头不执行读取和写入而提高速度。)为了保持可读性,我将假设数据库具有可管理的大小(100MB)和工作环境是上午9点至下午5点的工作,在非工作时间没有真正的压力或其他运行系统。
The first step would be to log into your local machine with root privileges. Once at the root shell, a MySQL user will need to be created with read only privileges. To do this, enter the MySQL shell using the command:
第一步是使用root权限登录本地计算机。一旦进入root shell,就需要使用只读权限创建MySQL用户。为此,请使用以下命令输入MySQL shell:
mysql -uroot -ppassword
Next, a user will need to be created with read only privileges to the database that needs to be backed up. In this case, a specific database does not need to be assigned to a user in case the script or process would be used at a later time. To create a user with full read privileges, enter these commands in the MySQL shell:
接下来,需要使用对需要备份的数据库的只读权限创建用户。在这种情况下,如果稍后将使用脚本或进程,则不需要将特定数据库分配给用户。要创建具有完全读取权限的用户,请在MySQL shell中输入以下命令:
grant SELECT on *.* TO backupdbuser@localhost IDENTIFIED BY ' backuppassword';
FLUSH PRIVILEGES;
With the MySQL user created, it's safe to exit the MySQL shell and drop back into the root shell using exit. From here, we'll need to create the script that we want to run our backup commands, this is easily accomplished using BASH. This script can be stored anywhere, as we'll be using a cron job to run the script nightly, for the sake of this example we'll place the script in a new directory we create called "backupscripts." To create this directory, use this command at the root shell:
创建MySQL用户后,退出MySQL shell并使用exit退回到root shell是安全的。从这里开始,我们需要创建我们想要运行备份命令的脚本,这可以使用BASH轻松完成。这个脚本可以存储在任何地方,因为我们将使用cron作业每晚运行脚本,为了这个例子,我们将脚本放在我们创建的名为“backupscripts”的新目录中。要创建此目录,请在root shell中使用此命令:
mkdir /backupscripts
We'll also need to create a directory to store our backups locally. We'll name this directory "backuplogs." Issue this command at the root shell to create the directory:
我们还需要创建一个目录来在本地存储我们的备份。我们将此目录命名为“backuplogs”。在root shell发出此命令以创建目录:
mkdir /backuplogs
The next step would be to log into your remote machine with root credentials and create a "backup user" with the command:
下一步是使用root凭据登录到远程计算机,并使用以下命令创建“备份用户”:
useradd -c "backup user" -p backuppassword backupuser
Create a directory for your backups:
为备份创建目录:
mkdir /backuplogs/
Before you log out, grab the IP address of the remote host for future reference using the command:
在您注销之前,请使用以下命令获取远程主机的IP地址以供将来参考:
ifconfig -a
eth0 is the standard interface for a wired network connection. Note this IP_ADDR.
eth0是有线网络连接的标准接口。请注意此IP_ADDR。
Finally, log out of the remote server and return to your original host.
最后,注销远程服务器并返回到原始主机。
Next we'll create the file that is our script on our host local machine, not the remote. We'll use VIM (don't hold it against me if you're a nano or emacs fan - but I'm not going to list how to use VIM to edit a file in here,) first create the file and using mysqldump, backup your database. We'll also be using scp to After the database has been created, compress your file for storage. Read the file to STDOUT to satisfy the instructions. Finally, check for files older than 7 days old. Remove them. To do this, your script will look like this:
接下来,我们将在我们的主机本地计算机上创建作为我们脚本的文件,而不是远程。我们将使用VIM(如果您是nano或emacs粉丝,请不要反对我 - 但我不打算在此处列出如何使用VIM编辑文件),首先创建文件并使用mysqldump ,备份你的数据库。我们也将使用scp在创建数据库之后,压缩文件以进行存储。将文件读取到STDOUT以满足说明。最后,检查7天以前的文件。删除它们。为此,您的脚本将如下所示:
vim /backupscripts/mysqldbbackup.sh
#!/bin/sh
# create a temporary file for the schema to be stored
BACKUPDIR = /backuplogs/
TMPFILE = tmpout.sql
CURRTIME = $(date +%Y%m%d).tgz
#backup your database
mysqldump -ubackupdbuser -pbackuppassword databasename > $BACKUPDIR$TMPFILE
#compress this file and store it locally with the current date
tar -zvcf /backuplogs/backupdb-$CURRTIME $BACKUPDIR$TMPFILE
#per instructions - cat the contents of the SQL file to STDOUT
cat $BACKUPDIR$TMPFILE
#cleanup script
# remove files older than 7 days old
find $BACKUPDIR -atime +7 -name 'backup-db-*.tgz' -exec rm {} \;
#remove the old backupdirectory from the remote server
ssh backupuser@remotehostip find /backuplogs/ -name 'backup-db-*.tgz' -exec rm {} \;
#copy the current backup directory to the remote server using scp
scp -r /backuplogs/ backupuser@remotehostip:/backuplogs/
#################
# End script
#################
With this script in place, we'll need to setup ssh keys, so that we're not prompted for a password every time our script runs. We'll do this with SSH-keygen and the command:
有了这个脚本,我们需要设置ssh密钥,这样我们的脚本每次运行时都不会提示输入密码。我们将使用SSH-keygen和命令执行此操作:
ssh-keygen -t rsa
Enter a password at the prompt - this creates your private key. Do not share this.
在提示符下输入密码 - 这会创建您的私钥。不要分享这个。
The file you need to share is your public key, it is stored in the file current_home/.ssh/id_rsa.pub. The next step is to transfer this public key to your remote host . To get the key use the command:
您需要共享的文件是您的公钥,它存储在文件current_home / .ssh / id_rsa.pub中。下一步是将此公钥传输到远程主机。要获取密钥,请使用以下命令:
cat current_home/.ssh/id_rsa.pub
copy the string in the file. Next ssh into your remote server using the command:
复制文件中的字符串。接下来使用以下命令ssh进入远程服务器:
ssh backupuser@remotehostip
Enter your password and then edit the file /.ssh/authorized_keys. Paste the string that was obtained from your id_rsa.pub file into the authorized_keys file. Write the changes to the file using your editor and then exit the editor. Log out of your remote server and test the RSA keys have worked by attempting to log into the remote server again by using the previous ssh command. If no password is asked for, it is working properly. Log out of the remote server again.
输入您的密码,然后编辑文件/.ssh/authorized_keys。将从id_rsa.pub文件中获取的字符串粘贴到authorized_keys文件中。使用编辑器将更改写入文件,然后退出编辑器。通过使用先前的ssh命令尝试再次登录远程服务器,注销远程服务器并测试RSA密钥是否正常工作。如果没有要求密码,它正常工作。再次注销远程服务器。
The final thing we'll need to do is create a cron job to run this every night after users have logged off. Using crontab, we'll edit the current users file (root) as to avoid all permission issues. *Note - this can have serious implications if there are errors in your scripts including deletion of data, security vulnerabilities, etc - double check all of your work and make sure you trust your own system, if this is not possible then an alternate user and permissions should be set up on the current server *. To edit your current crontab we'll issue the command:
我们需要做的最后一件事是创建一个cron作业,以便在用户注销后每晚运行。使用crontab,我们将编辑当前用户文件(root)以避免所有权限问题。 *注意 - 如果您的脚本中存在错误,包括删除数据,安全漏洞等,这可能会产生严重影响 - 仔细检查您的所有工作并确保您信任自己的系统,如果这是不可能的话,那么替代用户和应在当前服务器*上设置权限。要编辑当前的crontab,我们将发出命令:
crontab -e
While in the crontab editor (it'll open in your default text editor), we're going to set our script to run every night at 12:30am. Enter a new line into the editor:
在crontab编辑器中(它将在您的默认文本编辑器中打开),我们将设置我们的脚本每天晚上12:30运行。在编辑器中输入一个新行:
30 0 * * * bash /backupscripts/mysqldbbackup.sh
30 0 * * * bash /backupscripts/mysqldbbackup.sh
Save this file and exit the editor. To get your cronjob to run properly, we'll need to restart the crond service. To do this, issue the command:
保存此文件并退出编辑器。为了让你的cronjob正常运行,我们需要重新启动crond服务。为此,请发出以下命令:
/etc/init.d/crond restart
#1
22
Usually you run mysqldump to create a database copy and backups as follows:
通常运行mysqldump来创建数据库副本和备份,如下所示:
$ mysqldump -u user -p db-name > db-name.out
Copy db-name.out file using sftp/ssh to remote MySQL server:
使用sftp / ssh将db-name.out文件复制到远程MySQL服务器:
$ scp db-name.out user@remote.box.com:/backup
Restore database at remote server (login over ssh):
在远程服务器上恢复数据库(通过ssh登录):
$ mysql -u user -p db-name < db-name.out
OR
$ mysql -u user -p 'password' db-name < db-name.out
How do I copy a MySQL database from one computer/server to another?
如何将MySQL数据库从一台计算机/服务器复制到另一台?
Short answer is you can copy database from one computer/server to another using ssh or mysql client.
简而言之,您可以使用ssh或mysql客户端将数据库从一台计算机/服务器复制到另一台计算机/服
You can run all the above 3 commands in one pass using mysqldump and mysql commands (insecure method, use only if you are using VPN or trust your network):
您可以使用mysqldump和mysql命令在一次传递中运行以上所有3个命令(不安全的方法,仅在您使用VPN或信任您的网络时使用):
$ mysqldump db-name | mysql -h remote.box.com db-name
Use ssh if you don't have direct access to remote mysql server (secure method):
如果您无法直接访问远程mysql服务器(安全方法),请使用ssh:
$ mysqldump db-name | ssh user@remote.box.com mysql db-name
OR
$ mysqldump -u username -p'password' db-name | ssh user@remote.box.com mysql -u username -p'password db-name
You can just copy table called foo to remote database (and remote mysql server remote.box.com) called bar using same syntax:
您可以使用相同的语法将名为foo的表复制到名为bar的远程数据库(和远程mysql服务器remote.box.com):
$ mysqldump db-name foo | ssh user@remote.box.com mysql bar
OR
$ mysqldump -u user -p'password' db-name foo | ssh user@remote.box.com mysql -u user -p'password' db-name foo
Almost all commands can be run using pipes under UNIX/Linux oses.
几乎所有命令都可以在UNIX / Linux下使用管道运行。
More from Reference
更多来自参考
Regards,
#2
14
If you have Root, you might find it quicker to avoid mysqldump
. You can create the DB on the destination server, and copy the database files directly. Assuming user
has access to the destination server's mysql directory:
如果你有Root,你可能会发现避免使用mysqldump更快。您可以在目标服务器上创建数据库,并直接复制数据库文件。假设用户可以访问目标服务器的mysql目录:
[root@server-A]# /etc/init.d/mysqld stop
[root@server-A]# cd /var/lib/mysql/[databasename]
[root@server-A]# scp * user@otherhost:/var/lib/mysql/[databasename]
[root@server-A]# /etc/init.d/mysqld start
Important things here are: Stop mysqld on both servers before copying DB files, make sure the file ownership and permissions are correct on the destination before starting mysqld on the destination server.
这里重要的是:在复制DB文件之前在两台服务器上停止mysqld,确保在目标服务器上启动mysqld之前,目标上的文件所有权和权限是正确的。
[root@server-B]# chown mysql:mysql /var/lib/mysql/[databasename]/*
[root@server-B]# chmod 660 /var/lib/mysql/[databasename]/*
[root@server-B]# /etc/init.d/mysqld start
With time being your priority here, the use of compression will depend on whether the time lost waiting for compression/decompression (with something like gzip
) will be greater than the time wasted transmitting uncompressed data; that is, the speed of your connection.
由于时间是你的优先考虑,压缩的使用取决于等待压缩/解压缩(用gzip之类的东西)的时间是否大于传输未压缩数据所浪费的时间;也就是你的连接速度。
#3
2
For an automated way to backup your MySQL database:
对于备份MySQL数据库的自动方式:
The prerequisites to doing any form of backup is to find the ideal time of day to complete the task without hindering performance of running systems or interfere with users. On that note, the size of the database must be taken into consideration along with the I/O speed of the drives - this becomes exponentially more important as the database grows ( another factor that comes to mind is the number of drives, as having an alternate drive where the database is not stored would increase the speed due to the heads not performing both reads and writes.) For the sake of keeping this readable I'm going to assume the database is of a manageable size ( 100MB ) and the work environment is a 9am-5pm job with no real stress or other running systems on off hours.
执行任何形式的备份的先决条件是找到完成任务的理想时间,而不会妨碍运行系统的性能或干扰用户。在这方面,必须考虑数据库的大小以及驱动器的I / O速度 - 随着数据库的增长,这变得越来越重要(想到的另一个因素是驱动器的数量,因为有一个未存储数据库的备用驱动器会因为磁头不执行读取和写入而提高速度。)为了保持可读性,我将假设数据库具有可管理的大小(100MB)和工作环境是上午9点至下午5点的工作,在非工作时间没有真正的压力或其他运行系统。
The first step would be to log into your local machine with root privileges. Once at the root shell, a MySQL user will need to be created with read only privileges. To do this, enter the MySQL shell using the command:
第一步是使用root权限登录本地计算机。一旦进入root shell,就需要使用只读权限创建MySQL用户。为此,请使用以下命令输入MySQL shell:
mysql -uroot -ppassword
Next, a user will need to be created with read only privileges to the database that needs to be backed up. In this case, a specific database does not need to be assigned to a user in case the script or process would be used at a later time. To create a user with full read privileges, enter these commands in the MySQL shell:
接下来,需要使用对需要备份的数据库的只读权限创建用户。在这种情况下,如果稍后将使用脚本或进程,则不需要将特定数据库分配给用户。要创建具有完全读取权限的用户,请在MySQL shell中输入以下命令:
grant SELECT on *.* TO backupdbuser@localhost IDENTIFIED BY ' backuppassword';
FLUSH PRIVILEGES;
With the MySQL user created, it's safe to exit the MySQL shell and drop back into the root shell using exit. From here, we'll need to create the script that we want to run our backup commands, this is easily accomplished using BASH. This script can be stored anywhere, as we'll be using a cron job to run the script nightly, for the sake of this example we'll place the script in a new directory we create called "backupscripts." To create this directory, use this command at the root shell:
创建MySQL用户后,退出MySQL shell并使用exit退回到root shell是安全的。从这里开始,我们需要创建我们想要运行备份命令的脚本,这可以使用BASH轻松完成。这个脚本可以存储在任何地方,因为我们将使用cron作业每晚运行脚本,为了这个例子,我们将脚本放在我们创建的名为“backupscripts”的新目录中。要创建此目录,请在root shell中使用此命令:
mkdir /backupscripts
We'll also need to create a directory to store our backups locally. We'll name this directory "backuplogs." Issue this command at the root shell to create the directory:
我们还需要创建一个目录来在本地存储我们的备份。我们将此目录命名为“backuplogs”。在root shell发出此命令以创建目录:
mkdir /backuplogs
The next step would be to log into your remote machine with root credentials and create a "backup user" with the command:
下一步是使用root凭据登录到远程计算机,并使用以下命令创建“备份用户”:
useradd -c "backup user" -p backuppassword backupuser
Create a directory for your backups:
为备份创建目录:
mkdir /backuplogs/
Before you log out, grab the IP address of the remote host for future reference using the command:
在您注销之前,请使用以下命令获取远程主机的IP地址以供将来参考:
ifconfig -a
eth0 is the standard interface for a wired network connection. Note this IP_ADDR.
eth0是有线网络连接的标准接口。请注意此IP_ADDR。
Finally, log out of the remote server and return to your original host.
最后,注销远程服务器并返回到原始主机。
Next we'll create the file that is our script on our host local machine, not the remote. We'll use VIM (don't hold it against me if you're a nano or emacs fan - but I'm not going to list how to use VIM to edit a file in here,) first create the file and using mysqldump, backup your database. We'll also be using scp to After the database has been created, compress your file for storage. Read the file to STDOUT to satisfy the instructions. Finally, check for files older than 7 days old. Remove them. To do this, your script will look like this:
接下来,我们将在我们的主机本地计算机上创建作为我们脚本的文件,而不是远程。我们将使用VIM(如果您是nano或emacs粉丝,请不要反对我 - 但我不打算在此处列出如何使用VIM编辑文件),首先创建文件并使用mysqldump ,备份你的数据库。我们也将使用scp在创建数据库之后,压缩文件以进行存储。将文件读取到STDOUT以满足说明。最后,检查7天以前的文件。删除它们。为此,您的脚本将如下所示:
vim /backupscripts/mysqldbbackup.sh
#!/bin/sh
# create a temporary file for the schema to be stored
BACKUPDIR = /backuplogs/
TMPFILE = tmpout.sql
CURRTIME = $(date +%Y%m%d).tgz
#backup your database
mysqldump -ubackupdbuser -pbackuppassword databasename > $BACKUPDIR$TMPFILE
#compress this file and store it locally with the current date
tar -zvcf /backuplogs/backupdb-$CURRTIME $BACKUPDIR$TMPFILE
#per instructions - cat the contents of the SQL file to STDOUT
cat $BACKUPDIR$TMPFILE
#cleanup script
# remove files older than 7 days old
find $BACKUPDIR -atime +7 -name 'backup-db-*.tgz' -exec rm {} \;
#remove the old backupdirectory from the remote server
ssh backupuser@remotehostip find /backuplogs/ -name 'backup-db-*.tgz' -exec rm {} \;
#copy the current backup directory to the remote server using scp
scp -r /backuplogs/ backupuser@remotehostip:/backuplogs/
#################
# End script
#################
With this script in place, we'll need to setup ssh keys, so that we're not prompted for a password every time our script runs. We'll do this with SSH-keygen and the command:
有了这个脚本,我们需要设置ssh密钥,这样我们的脚本每次运行时都不会提示输入密码。我们将使用SSH-keygen和命令执行此操作:
ssh-keygen -t rsa
Enter a password at the prompt - this creates your private key. Do not share this.
在提示符下输入密码 - 这会创建您的私钥。不要分享这个。
The file you need to share is your public key, it is stored in the file current_home/.ssh/id_rsa.pub. The next step is to transfer this public key to your remote host . To get the key use the command:
您需要共享的文件是您的公钥,它存储在文件current_home / .ssh / id_rsa.pub中。下一步是将此公钥传输到远程主机。要获取密钥,请使用以下命令:
cat current_home/.ssh/id_rsa.pub
copy the string in the file. Next ssh into your remote server using the command:
复制文件中的字符串。接下来使用以下命令ssh进入远程服务器:
ssh backupuser@remotehostip
Enter your password and then edit the file /.ssh/authorized_keys. Paste the string that was obtained from your id_rsa.pub file into the authorized_keys file. Write the changes to the file using your editor and then exit the editor. Log out of your remote server and test the RSA keys have worked by attempting to log into the remote server again by using the previous ssh command. If no password is asked for, it is working properly. Log out of the remote server again.
输入您的密码,然后编辑文件/.ssh/authorized_keys。将从id_rsa.pub文件中获取的字符串粘贴到authorized_keys文件中。使用编辑器将更改写入文件,然后退出编辑器。通过使用先前的ssh命令尝试再次登录远程服务器,注销远程服务器并测试RSA密钥是否正常工作。如果没有要求密码,它正常工作。再次注销远程服务器。
The final thing we'll need to do is create a cron job to run this every night after users have logged off. Using crontab, we'll edit the current users file (root) as to avoid all permission issues. *Note - this can have serious implications if there are errors in your scripts including deletion of data, security vulnerabilities, etc - double check all of your work and make sure you trust your own system, if this is not possible then an alternate user and permissions should be set up on the current server *. To edit your current crontab we'll issue the command:
我们需要做的最后一件事是创建一个cron作业,以便在用户注销后每晚运行。使用crontab,我们将编辑当前用户文件(root)以避免所有权限问题。 *注意 - 如果您的脚本中存在错误,包括删除数据,安全漏洞等,这可能会产生严重影响 - 仔细检查您的所有工作并确保您信任自己的系统,如果这是不可能的话,那么替代用户和应在当前服务器*上设置权限。要编辑当前的crontab,我们将发出命令:
crontab -e
While in the crontab editor (it'll open in your default text editor), we're going to set our script to run every night at 12:30am. Enter a new line into the editor:
在crontab编辑器中(它将在您的默认文本编辑器中打开),我们将设置我们的脚本每天晚上12:30运行。在编辑器中输入一个新行:
30 0 * * * bash /backupscripts/mysqldbbackup.sh
30 0 * * * bash /backupscripts/mysqldbbackup.sh
Save this file and exit the editor. To get your cronjob to run properly, we'll need to restart the crond service. To do this, issue the command:
保存此文件并退出编辑器。为了让你的cronjob正常运行,我们需要重新启动crond服务。为此,请发出以下命令:
/etc/init.d/crond restart