当前位置:网站首页>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
边栏推荐
- 4. File modification
- [unity3d] GUI control
- Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
- 继承day01
- Performance analysis of user login TPS low and CPU full
- 【若依(ruoyi)】设置主题样式
- Installation and use tutorial of cobaltstrike-4.4-k8 modified version
- Audio-AudioRecord Binder通信机制
- Mysql database operation
- [ruoyi] ztree custom icon (iconskin attribute)
猜你喜欢
The real machine cannot access the shooting range of the virtual machine, and the real machine cannot Ping the virtual machine
适合程序员学习的国外网站推荐
[ruoyi] enable Mini navigation bar
Precautions for single chip microcomputer anti reverse connection circuit
Explore pointers and pointer types in depth
Linear programming matlab
建模规范:命名规范
Tomb. Weekly update of Finance (February 7 - February 13)
MySQL advanced notes
Problems encountered in 2022 work IV
随机推荐
Communication between microservices
Modeling specifications: naming conventions
Mysql database operation
[Li Kou] the second set of the 280 Li Kou weekly match
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
The difference between sizeof and strlen in C language
Distributed service framework dobbo
【概念】Web 基础概念认知
IPv6 jobs
How to choose PLC and MCU?
Apt installation ZABBIX
【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
JS音乐在线播放插件vsPlayAudio.js
1.16 - 校验码
Linear programming matlab
Recommended foreign websites for programmers to learn
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
蓝色样式商城网站页脚代码
Daily question brushing plan-2-13 fingertip life