当前位置:网站首页>Mysqldump data backup
Mysqldump data backup
2022-07-06 03:13:00 【Rookie ~ ~】
In our last blog, we talked about using mysqlbinlog Tools (mysql Native tools ) Mind parsing a large number of binlog Log files , And use binary logs Data recovery Application practice of , In this blog, let's talk about the command of turning off data backup first , Because we usually work in shell Next , And deployed in the background server or cloud mysql, Most have made some restrictions , We may not be able to connect directly to the database of the background service locally 3306 On port , Generally, there will be intermediate keys of networks such as firewalls , No conditions GUI( GUI tools ) Mouse operation for data backup and so on , Only by command , And the command is also the fastest , So this blog talks about commonly used The data backup , We usually pass mysqldump Conduct .
stay linux shell Execute the following command , You can mytest Library user The data of the table is exported to .sql In file ( Exporting is not just data ,SQL Statements are also exported )
vim user.sql see user.sql The contents of the document are as follows :
Now? mytest Inside the library , We deleted the table , Or we are moving towards data migration , Rebuild this table on another library . We have this sql Script in root Under the root directory , Not enough permissions , It should be executed under ordinary users , So the user.sql Move to ordinary users ( Or we can start with ordinary users mysqldump -u root -p mytest user > ~/user.sql
hold mytest Library user The data of the table is exported to .sql In file , There is no need to perform the next steps , Direct execution source /home/admin/user.sql
, You can recover user Tables and data )
Now? user.sql yes root The file of , We change a subordinate , So that ordinary users can also operate
And then we source, Is equivalent to .sql
Execute the script again
user The table and data are all recovered , With .sql Script for , Can be in any mysql Rebuild the database table and data on the database
We can also export pure table data directly
user.txt The contents are as follows :
This way user All the data in the table are exported , We'll use it again python perhaps go When writing some scripts for data analysis , Can pass -t As a separator, get the data of each field for additional data analysis , For example, analyze user behavior , Create user portraits, etc .
mysqldump Data backup command summary
- Export database and table creation SQL
// Export all libraries
mysqldump -u user name -p --all-databases > ~/xxx.sql
// You can export multiple libraries at a time
mysqldump -u user name -p --databases db1[db2] > ~/xxx.sql
// Export the library or a table in the Library
mysqldump -u user name -p dbname [tablename]> ~/xxx.sql
- Export pure data
mysql -u user name -p -D school -e 'select * from user where age>10' > ~/user.txt
- Via backup .sql, Import data , Building database and building tables
Sign in mysql, stay mysql Of shell Execute the following statement on
source ~/school.sql
Or directly at linux Of shell perform
cat ~/data.sql|mysql -u root -p
In this way, the data we backed up before can be sent to mysql In the library table of
边栏推荐
- Reverse repackaging of wechat applet
- 【概念】Web 基础概念认知
- Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
- Redis cache breakdown, cache penetration, cache avalanche
- Jenkins basic knowledge ----- detailed explanation of 03pipeline code
- 八道超经典指针面试题(三千字详解)
- Classic interview question [gem pirate]
- 建模规范:命名规范
- 下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
- SD卡报错“error -110 whilst initialising SD card
猜你喜欢
如何做好功能测试
Linear regression and logistic regression
C # create self host webservice
2022工作中遇到的问题四
XSS challenges bypass the protection strategy for XSS injection
Getting started with applet cloud development - getting user search content
How to do function test well
js 正则过滤和增加富文本中图片前缀
My C language learning record (blue bridge) -- on the pointer
真机无法访问虚拟机的靶场,真机无法ping通虚拟机
随机推荐
Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration
【指针训练——八道题】
有没有完全自主的国产化数据库技术
[padding] an error is reported in the prediction after loading the model weight attributeerror: 'model' object has no attribute '_ place‘
【若依(ruoyi)】设置主题样式
Explore pointers and pointer types in depth
These are not very good
Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
How to choose PLC and MCU?
Audio audiorecord binder communication mechanism
Precautions for single chip microcomputer anti reverse connection circuit
Leetcode problem solving -- 99 Restore binary search tree
codeforces每日5題(均1700)-第六天
Misc (eternal night), the preliminary competition of the innovation practice competition of the National College Students' information security competition
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
【Unity3D】GUI控件
[unity3d] GUI control
js凡客banner轮播图js特效
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
Redis SDS principle