mysqldump

mysql escaping single and double quotes

自闭症网瘾萝莉.ら 提交于 2020-01-02 10:59:33
问题 I have a script that i am writing to move certain fields to a new db like $results = mysql_query ( "SELECT body, title FROM $source_db.Post" ); while ($row = mysql_fetch_array($results)) { if(mysql_num_rows($users_result) > 0){ $insert = "INSERT INTO wp_posts (`body`,`title`) VALUES ('{$row['body']}', '{$row['row']}')"; mysql_query($insert); } } but as you can see the query will break everytime due to the single and double quotes, is there a solution to this problem like herdok or something

generating database with different name from mysqldump backup

半腔热情 提交于 2020-01-01 09:42:20
问题 The database "db" is backuped in backup.sql. Is there a way to restore database from script with different from "db" name? thank you in advance! 回答1: Sure, when you import it you do this right: mysql -uuser -ppassword databasename < mydump.sql You can put anything you want where I wrote databasename - as long as that database actually exists :) 回答2: If the name of the database is include the SQL file, I didn't find any other way than modify the SQL file. My favorite command to do it : sed -i

Skip or ignore definers in Mysqldump

情到浓时终转凉″ 提交于 2020-01-01 09:37:29
问题 I was wondering if I can prevent mysqldump inserting this commands /*!50017 DEFINER=`root`@`localhost`*/ Or if I have to do it afterwards with sed, for example Thanks! 回答1: This issue has been around since 2006 with no sign of ever being fixed. I have, however, piped it through grep (linux only) to trim out the definer lines before writing the dump file: mysqldump -u dbuser -p dbname | grep -v 'SQL SECURITY DEFINER' > dump.sql A bit of a mouthful (or keyboardful?) but I think it's the only

Importing MySQL database from one server to another

房东的猫 提交于 2020-01-01 04:22:11
问题 I have got two dedicated servers with root access. Both are running Linux. I want to import database from Server1 to Server2. I have already created an empty database on Server2. I want to know Linux command through which I can import database directly? Is there such a feature? Can I use mysqldump? I want to avoid first taking database backup on server1, then moving that file to server2, and then importing that file. Can import be done directly using some command? Thanks 回答1: If you want to

navicat for mysql (10038)如何解决

让人想犯罪 __ 提交于 2020-01-01 01:44:14
1、授权(youpassword修改为你的密码) #本机登陆mysql: $:mysql -u root -p #改变数据库: mysql>use mysql; #从所有主机: mysql>grant all privileges on *.* to 'root'@'%' identified by 'youpassword' with grant option; mysql>flush privileges; 2、修改/etc/mysql/my.conf 找到 bind-address = 127.0.0.1 这一行 改为 bind-address = 0.0.0.0 即可 参考文章 配置和管理msyql:   1. 修改mysql最大连接数:cp support-files/my-medium.cnf ./my.cnf,vim my.cnf,增加或修改max_connections=1024   关于my.cnf:mysql按照下列顺序搜索my.cnf:/etc,mysql安装目录,安装目录下的data。/etc下的是全局设置。   2. 启动mysql:/usr/local/mysql/bin/mysqld_safe --user=mysql &     查看mysql版本:mysqladmin -u root -p version     注

MariaDB10.3 版本表

痞子三分冷 提交于 2019-12-31 23:30:04
继续学习新技术。。。 未完待续 system_versioning_alter_history='KEEP' system_versioning_asof=default system_versioning_innodb_algorithm_simple == keep default value -->>>ON --copied, below set global system_versioning_alter_history = ‘KEEP’; --否则默认不能执行DDL修改表结构。 增加字段时,要加上after关键字,否则会在te字段后面,造成同步失败。例: alter table t1 add column address varchar(500) after name; mysqldump工具不会导出历史数据,所以在做备份时,可以通过Percona XtraBackup热备份工具来备份物理文件。 搭建从库时,如果你用mysqldump工具,要先导出表结构文件,再导出数据。 ------- copy end ---------- 来源: 51CTO 作者: wx5d3fa9bac3f22 链接: https://blog.51cto.com/14475579/2434965

How to Export & Import Existing User (with its Privileges!)

回眸只為那壹抹淺笑 提交于 2019-12-31 17:39:35
问题 I have an existing MySQL instance (test), containing 2 databases and a few users each having different access privileges to each database. I now need to duplicate one of the databases (into production) and the users associated with it. Duplicating the database was easy: Export: mysqldump --no-data --tables -u root -p secondb >> secondb_schema.sql Import: mysql -u root -p -h localhost secondb < secondb_schema.sql I didn't find, however, a straightforward way to export and import users , from

How do I use mysqldump to export only the CREATE TABLE commands?

蹲街弑〆低调 提交于 2019-12-31 08:42:54
问题 I'm trying to use mysqldump to export only the DB schema -- no data, no additional SQL comments, just the CREATE TABLE commands. Here's what I've got so far: mysqldump -h localhost -u root -p --no-data --compact some_db It almost achieves what I want, but I'd like to eliminate the "character set" lines (those like the first 3 lines in the example output below). Is there a mysqldump option to do that? /*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET @saved_cs_client = @

mysql 导出表结构和表数据 mysqldump用法

。_饼干妹妹 提交于 2019-12-30 22:58:25
mysql 导出表结构和表数据 mysqldump用法 命令行下具体用法如下: mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名; 导出整个数据库结构和数据 mysqldump -h localhost -u用户名 -p密码 数据库名称 > dump.sql(自己编辑数据库文件名,或指定路径) 导出单个数据表结构和数据 mysqldump -h localhost -u用户名 -p密码 数据库名称 表名称 > test.sql(自己编辑数据库文件名,或指定路径) 导出整个数据库结构(不包含数据) mysqldump -h localhost -u用户名 -p密码 -d 数据库名称 > test.sql(自己编辑数据库文件名,或指定路径) 导出单个数据表结构(不包含数据) mysqldump -h localhost -u用户名 -p密码 -d 数据库名 表名 > test.sql(自己编辑数据库文件名,或指定路径) mysqldump 备份导出数据排除某张表 就用 --ignore-table=dbname.tablename参数就行了。 mysqldump -uroot -proot -hlocalhost -P3306 数据库名称 --ignore-table=数据库名称.表名称 > test.sql(自己编辑数据库文件名,或指定路径) 来源:

InnoDB tables exist in MySQL but says they do not exist after copying database to new server

天涯浪子 提交于 2019-12-30 02:31:25
问题 I used mysqldump to export my database and then I imported it into MySQL on my other server. I can now see all my tables if I do "show tables" but I can't actually select from or describe any of them. ERROR 1146 (42S02): Table 'mydatabase.user' doesn't exist All of my tables are InnoDB. I saw one issue people had where they were using old_passwords, so I explicitly set that to 0 in my.cnf and I made sure all of the passwords in the mysql table were 41 hexadecimal digits as they should be for