当前位置:网站首页>Linux regularly backs up MySQL database
Linux regularly backs up MySQL database
2022-07-06 06:00:00 【amu】
For data security , It is necessary to back up your database regularly , Of course , You can't back up manually every time , It's not just trouble , and , In case you forget to back up , If something goes wrong, it's over . So I use a timer cron The task comes from the process of Automation .
Create script file backupdb.sh
The following script db_userdb_passwddb_namebackup_name Replace with your own information .
#!/bin/bash
db_user="username"
db_passwd="pwd"
db_name="dbname"
backup_name="$(date +"%Y%m%d%H%M%S")"
/usr/bin/mysqldump -u$db_user -p$db_passwd $db_name >> /path/to/$backup_name.sql
Add execute permission
chmod +x backupdb.sh
establish cron Timing task
perform crontab -e, Prompt you to choose editor , You can choose according to your personal preference ( I chose vim
no crontab for admin - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]: 2Then input the following content on the pop-up edit page :
0 1 * * * /home/admin/backupdb.shThe above line means , Every morning 1 Point to perform
/home/admin/backupdb.sh. Of course, you can choose the backup frequency according to your own situation , About cron Use , You can refer to what I wrote before This article .
p.s. The following may be prompted , But it does not affect the backup :
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Tips mysqldump Process permission error
Here's a hint :
mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces
Description of the user No permission for this database , The solution is 2 individual .
Update the permissions of database users . Use mysqldump The --no-tablespaces Options run .
Method 1: Update user rights
Grant to users PROCESS Permissions may be fixed mysqldump The simplest option of process permission error . But it will bring safety problem .
Log in to the database as an administrator user , Grant users you need to use PROCESS jurisdiction :
GRANT PROCESS ON *.* TO [email protected];
p.s. PROCESS It is a global level permission . It cannot be applied to a single database . Global permissions are either administrative permissions , Or apply to MySQL All databases on the server . Trying to grant them on a single database displays the following error :
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
To grant permissions to all databases , You must use ON *.* ... grammar .
Method 2: Use --no-tablespaces Options If you don't want to assign global level permissions to the users you use , Must be specified when dumping the database --no-tablespaces Options .
mysqldump --no-tablespaces -u user -ppass dbname >> backupfile.sql
give PROCESS The security of permissions
according to MySQL file ,[PROCESS jurisdiction ] It controls the access to information of the statement being executed in the session . This is a kind of server management permission , So it's best to grant it to all users . This is because it may display the text in the currently executing query . therefore , Any having PROCESS Users with permissions can see the queries sent by others . For example, similar UPDATE user SET password=PASSWORD Query for , Private content may be displayed .
边栏推荐
- Yunxiaoduo software internal test distribution test platform description document
- [experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
- The usage and difference between strlen and sizeof
- 单元测试的意义
- Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
- Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
- Bit operation rules
- How Huawei routers configure static routes
- About PHP startup, mongodb cannot find the specified module
- [experience] install Visio on win11
猜你喜欢

Classes and objects (I) detailed explanation of this pointer

nodejs实现微博第三方登录

Station B Liu Erden softmx classifier and MNIST implementation -structure 9

Yunxiaoduo software internal test distribution test platform description document

How to use the container reflection method encapsulated by thinkphp5.1 in business code

Grant Yu, build a web page you want from 0

如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
![[course notes] Compilation Principle](/img/cc/34e86087cc5698f9bed91675369265.jpg)
[course notes] Compilation Principle

H3C V7版本交换机配置IRF

What preparations should be made for website server migration?
随机推荐
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
Station B, Mr. Liu Er - multiple logistic regression, structure 7
Embedded interview questions (I: process and thread)
Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
【无标题】
LTE CSFB process
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
The usage and difference between strlen and sizeof
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
公司视频加速播放
Luogu [Beginner Level 4] array p1427 number game of small fish
华为BFD的配置规范
The difference and usage between continue and break
Mysql database master-slave cluster construction
Sqlmap tutorial (III) practical skills II
Go language -- language constants
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
数学三大核心领域概述:代数
[email protected]树莓派