mysqldump

MySQL中使用mysqldump和source命令实现备份与还原

吃可爱长大的小学妹 提交于 2019-11-29 13:55:10
mysqldump工具 的使用 导出要用到MySQL的mysqldump工具,基本用法是: shell> mysqldump [OPTIONS] database [tables] 如果你不给定任何表,整个数据库将被导出。 通过执行 mysqldump --help ,你能得到你mysqldump的版本支持的选项表。 注意,如果你运行mysqldump没有--quick或--opt选项,mysqldump将在导出结果前装载整个结果集到内存中,如果你正在导出一个大的数据库,这将可能是一个问题。 mysqldump支持下列选项: --add-locks 在每个表导出之前增加LOCK TABLES并且之后UNLOCK TABLE。(为了使得更快地插入到MySQL)。 --add-drop-table 在每个create语句之前增加一个drop table。 --allow-keywords 允许创建是关键词的列名字。这由表名前缀于每个列名做到。 -c, --complete-insert 使用完整的insert语句(用列名字)。 -C, --compress 如果客户和服务器均支持压缩,压缩两者间所有的信息。 --delayed 用INSERT DELAYED命令插入行。 -e, --extended-insert 使用全新多行INSERT语法。(给出更紧缩并且更快的插入语句) -#,

Which are the proper privileges to mysqldump for the Error Access denied when executing 'SELECT INTO OUTFILE'.?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 13:36:46
问题 backup user has BackupAdmin role and ALL privileges (object rights, DDL, GRANT). cmd> mysqldump --routines=TRUE --tab=C:\tmp -h localhost -u backup -pbackup schemalocal cmd> mysqldump: Got error: 1045: Access denied for user 'backup'@'%' (using password: YES) when executing 'SELECT INTO OUTFILE' The only way to make it work is to give DBA role to backup account, but that is a security risk so I want to give it only the neccesary rights. Which are them? 回答1: You need the FILE privilege in

mysql 命令行导入导出.sql文件

末鹿安然 提交于 2019-11-29 12:39:56
window下 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u dbuser -p dbname > dbname.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u dbuser -p dbname users> dbname_users.sql 3.导出一个数据库结构 mysqldump -u dbuser -p -d --add-drop-table dbname >d:/dbname_db.sql -d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table 4.导入数据库 常用source 命令 进入mysql数据库控制台,如 mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source d:/dbname.sql 1. 导入数据到数据库 mysql -uroot -D数据库名 1. 导入数据到数据库中得某个表 mysql -uroot -D数据库名 表名 D:\APMServ5.2.6\MySQL5.1\bin>mysqldump -u root -p erp lightinthebox_tags

必会的MySQL操作方法

独自空忆成欢 提交于 2019-11-29 11:53:56
远程登陆数据库: CMD命令如下。 mysql -h IP地址 -P 端口 -u 用户名 -p密码 (-p和密码之间,不能有空格) mysql -h 192.168.0.102 -P 3306 -u user -p123456 一、备份常用操作基本命令 1、备份命令mysqldump格式 格式:mysqldump -h主机名 -P端口 -u用户名 -p密码 –database 数据库名 > 文件名.sql 2、备份MySQL数据库为带删除表的格式 备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库。 mysqldump –add-drop-table -uusername -ppassword -database databasename > backupfile.sql 3、直接将MySQL数据库压缩备份 mysqldump -hhostname -uusername -ppassword -database databasename | gzip > backupfile.sql.gz 4、备份MySQL数据库某个(些)表 mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 > backupfile.sql 5

Free space in MySQL after deleting tables & columns?

随声附和 提交于 2019-11-29 11:22:49
I have a database of around 20GB. I need to delete 5 tables & drop a few columns in some other 3 tables. Dropping 5 tables with free some 3 GB and dropping columns in other tables should free another 8GB. How do I reclaim this space from MySQL. I've read dumping the database and restoring it back as one of the solution but I'm not really sure how that works, I am not even sure if this only works for deleting the entire database or just parts of it? Please suggest how to go about this. THanks. From the comments, it sounds like you're using InnoDB without the file per table option. Reclaiming

MySQL backup and restore from command line

a 夏天 提交于 2019-11-29 10:34:45
问题 I am using Command line to backup and restore MYSQL Database. Let use I m having a Database Data1 having Views and Procedures in it. When in Cmd line , I use mysqldump i.e ..>bin> mysqldump -u root -proot Data1 > Datafile.mysql When I use above Cmd, It creates a Backup file on bin Folder of Mysql with Dtafile.mysql Name. but the thing is it creates Back Up of Only Tables, Not Procedures. And when I m restoring it in a Blank Database "Data2" ..bin> mysql - u root -proot Data2 < Dataafile.mysql

Mysqlmysql: [Warning] Using a password on the command line interface can be insecure

本秂侑毒 提交于 2019-11-29 10:01:17
mysql: [Warning] Using a password on the command line interface can be insecure MySQL 5.6 警告信息 command line interface can be insecure 在命令行输入密码,就会提示这些安全警告信息。 Warning: Using a password on the command line interface can be insecure. 注: mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都会输出这样的警告信息. 1、针对mysql mysql -u root -pPASSWORD 改成mysql -u root -p 在输入密码即可. 2、mysqldump就比较麻烦了,通常都写在scripts脚本中。 解决方法一: 对于 mysqldump 要如何避免出现(Warning: Using a password on the command line interface can be insecure.) 警告信息呢? vim /etc/mysql/my.cnf [mysqldump] user=your_backup_user_name password=your_backup_password

Fix serialized data broken due to editing MySQL database in a text editor?

拜拜、爱过 提交于 2019-11-29 08:03:07
问题 Background: I downloaded a *.sql backup of my WordPress site's database, and replaced all instances of the old database table prefix with a new one (e.g. from the default wp_ to something like asdfghjkl_ ). I've just learnt that WordPress uses serialized PHP strings in the database, and what I did will have messed with the integrity of the serialized string lengths. The thing is, I deleted the backup file just before I learnt about this (as my website was still functioning fine), and

How do I dump MySQL file without Foreign Keys via command line?

落花浮王杯 提交于 2019-11-29 07:22:24
I need to export a large database without foreign keys. What is the command to do this? This is what I tried but I know this is incorrect. mysqldump -u root -p DBNAME SET FOREIGN_KEY_CHECKS = 0; | gzip > database.sql.gzip philwinkle From this SO thread: Can you automatically create a mysqldump file that doesn't enforce foreign key constraints? The mysqldump command included with MySQL 5.0.51 (and according to the change log versions since 4.1.1) does switch off foreign key checks. By default, mysqldump includes the following line at the top of the dump file: /*!40014 SET @OLD_FOREIGN_KEY

Mysql主从复制配置

落爺英雄遲暮 提交于 2019-11-29 07:16:10
Mysql 主从复制是一台服务器充当主服务器,另一台或多台服务器充当从服务器,主机自动复制到从机。对于多级复制,数据服务器即可充当主机,也可充当从机。 Mysql 复制的基础是主服务器对数据库修改记录二进制日志 binlog ,从服务器通过主服务器的 binlog 自动执行更新。 下面以 InnoDB 引擎为例,说明配置主从复制的方法。 1 配置 /etc/my.cnf 修改主服务器 my.cnf ,在 [mysqld] 中增加如下内容: ## 打开 binlog log-bin=mysql-bin ## 服务器 ID 。服务器之间不能有重复 ID ,一般主是 1 server-id = 1 ## 指定不写 binlog 的数据库,不同步系统库 binlog-ignore-db = mysql binlog-ignore-db = information_schema binlog-ignore-db = cluster ## 指定写二进制的数据库,多个要多行 replicate-do-db = DB_Test ## 指定跨库更新也同步的数据库。和 replicate-do-db 相同多行 replicate-wild-do-table=DB\_Test.% 修改从服务器 my.cnf ,设置 server-id=2 。 另外,主从服务器的 ip 和端口信息配置不在 my.cnf