查看数据库的版本信息
mysqladmin -uroot -p123 version
#csv2db
mysqlimport -u root --password='123' -L -v --columns='name,price,productid,site,link,smallImage,bigImage,description,createdOn,modifiedOn,size,weight,wrap,material,packagingCount,stock,location,popularity,inStock,categories' --fields-terminated-by=',' --fields-enclosed-by='"' --fields-escaped-by='\\' --lines-terminated-by='\n' search ./model_product.csv
4.5.4. mysqldump — A Database Backup Program
The mysqldump client is a backup program originally written by Igor Romanenko. It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both. However,mysqldump can also be used to generate files in CSV, other delimited text, or XML format.
If you are doing a backup on the server and your tables all are MyISAM
tables, consider using the mysqlhotcopyinstead because it can accomplish faster backups and faster restores. See Section 4.6.9, “mysqlhotcopy — A Database Backup Program”.
There are three general ways to invoke mysqldump:
shell>mysqldump [
shell>options
]db_name
[tbl_name
...]mysqldump [
shell>options
] --databasesdb_name
...mysqldump [
options
] --all-databases
If you do not name any tables following db_name
or if you use the --databases
or --all-databases
option, entire databases are dumped.
mysqldump can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it. Buffering in memory can be a problem if you are dumping large tables. To dump tables row by row, use the --quick
option (or --opt
, which enables --quick
). The --opt
option (and hence --quick
) is enabled by default, so to enable memory buffering, use --skip-quick
.
================================
几个常用用例:
1.导出整个数据库
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3.导出一个数据库结构
mysqldump -u wcnc -p -d --add-drop-table smgp_apps_wcnc >d:\wcnc_db.sql
-d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table
4.导入数据库
常用source 命令
进入mysql数据库控制台,
如mysql -u root -p
mysql>use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql>source d:\wcnc_db.sql
#MySQLdump 数据库名 >数据库备份名
#mysqldump -A -u 用户名 -p密码 数据库名>数据库备份名
#mysqldump -d -A --add-drop-table -uroot -p >xxx.sql
#mysqldump 数据库名 >数据库备份名
#mysqldump -A -u用户名 -p密码 数据库名>数据库备份名
#mysqldump -d -A --add-drop-table -uroot -p >xxx.sql
1.导出结构不导出数据
Ruby 代码
mysqldump --opt -d 数据库名 -u root -p > xxx.sql
mysqldump --opt -d 数据库名 -u root -p > xxx.sql
2.导出数据不导出结构
Linux 代码
mysqldump -t 数据库名 -uroot -p > xxx.sql
mysqldump -t 数据库名 -uroot -p > xxx.sql
3.导出数据和表结构
Linux 代码
mysqldump 数据库名 -uroot -p > xxx.sql
mysqldump 数据库名 -uroot -p > xxx.sql
4.导出特定表的结构
Linux 代码
mysqldump -uroot -p -B 数据库名 --table 表名 > xxx.sql
mysqldump -uroot -p -B数据库名 --table 表名 > xxx.sql
导入数据:
由于mysqldump导出的是完整的SQL语句,所以用mysql客户程序很容易就能把数据导入了:
Linux 代码
#mysql 数据库名 < 文件名
#source /tmp/xxx.sql