mysql学习小札(2)-- 数据备份、还原、导入导出方法的简单总结_MySQL
一、数据的备份 1.mysqldump mysqldump -u user -h host -p dbname [tablename, [tablename...]] > filename.sql ■ 备份数据库中所有的表 → mysqldump -u root -p dbname > backup.sql ■ 备份数据库中某个表 → mysqldump -u root -p dbname tblname > backup.sql ■ 备份多个数据库 → mysqldump -u root -p --databases db1 db2 > backup.sql ■ 备份系统中所有的数据库 → mysqldump -u root -p --all-databases > backup.sql 注: 如果在服务器上,且表均为MYISAM表,应考虑使用mysqlhotcopy ☆☆☆
二、数据的还原 1.mysql ■ mysql -u user -p [dbname]
三、表的导出 1.mysqldump → shell下 mysqldump -T path -u root -p dabname [tables] [opt] ■ 只有制定了-T才能到处纯文本文件,path表述导出数据的目录 ■ opt选项(同下类似) --fields-terminated-by=value --fields-enclosed-by=value
--fields-optionally-enclosed-by=value --fields-escaped-by=value --line-terminated-by=value
注:value无需用‘’括起来
2.SELECT...INTO OUTFILE → 登陆mysql后 SELECT columunlist FROM tbl WHERE condition INTO OUTFILE 'filename' [OPT] ■ opt选项: FILEDS TERMINATED BY 'value' → 字段之间分隔符为value FILEDS [OPTIONALLY] ENCLOSED BY 'value' → 字段包围字符为value FILEDS ESCAPED BY 'value' → 设置转义字符为value LINES STARTING BY 'value' → 设置每行开头字符为value LINES TERMINATED BY 'value' → 设置每行结尾字符为value 注:通过opt可调整导出的filename中数据显示的样式,很有用! ☆☆☆☆☆
3.mysql命令 → shell下 mysql -u root -p --execute="SELECT 语句" dbname > filename.txt ■ mysql -u root -p --execute="SELECT * FROM tbl;" db > output.txt ■ mysql -u root -p --vertical --execute="SELECT ..." > ... → 将每行记录分多行显示 ■ mysql -u root -p --html --execute="..." db > ... → 导出到html文件(或用--xml)
四、表的导入 1.LOAD DATA INFILE LOAD DATA INFILE ‘filename.txt’ INTO TABLE tbl [OPT] [IGNORE number LINES] ■ OPT选项 → 同 SELECT ... INTO OUTFILE 一致 ■ IGNORE number LINES → 忽略filename.txt的前number行
2.mysqlimport mysqlimport -u root -p daname filename.txt [OPT] ■ OPT选项 → 同mysqldump,但了一个--ignore-lines=n ,当然还有很多其他的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)
