jamesstewy / go-mysqldump Goto Github PK
View Code? Open in Web Editor NEWCreate SQL dumps in Go without external dependencies
License: MIT License
Create SQL dumps in Go without external dependencies
License: MIT License
It would be great if you could group the insert in batches of thousand items, so that you get some notion of progress when executing the dump with mysql-workbench or other UIs.
source :
table get value is [awk '{print $2}']ใ
dump after:
'awk '{print $2}''
dump.go func createTableValues(db *sql.DB, name string) (string, error) {
for key, value := range data {
if value != nil && value.Valid {
dataStrings[key] = value.String
}
}
}
modify-->
for key, value := range data {
if value != nil && value.Valid {
rune := \'
dataStrings[key] = strings.Replace(value.String, "'", rune, -1)
}
}
Is there a way to dump just one table? I only see the entire db, which may be many many gb, and I just want to backup one table before doing an insert.
Hi,
it seems that strings are not escaped properly. e.g. If I open the dump file with Visual Studio Code I see lines like
('2','OPEN_DOOR_CLOSED','If there is a 'Open door' detected and this door is closed now, the message Open Door closed is send.','2018-04-24T16:09:42Z','2018-04-24T16:09:42Z','0','door_closed','0','0','8','0','0')
Hi, is there a way to restore a dump using go?
I tried execute the file but got the next error:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COL' at line 7
Also tried spliting the queries with ';' but doesn't work when there's a value with ';' inside.
Using the MySQL CLI or HeidiSQL works well.
I know that works using the cmd/exec package with MySQL CLI. But the target is use go only.
Maybe using a regex? any ideas?
such as sql:
SHOW CREATE TABLE `order`
# ok
SHOW CREATE TABLE order # error
here is code below:
func createTableSQL(db *sql.DB, name string) (string, error) {
// Get table creation SQL
var table_return sql.NullString
var table_sql sql.NullString
// fix it like this,thanks
err := db.QueryRow("SHOW CREATE TABLE `"+name+"`").Scan(&table_return, &table_sql)
if err != nil {
return "", err
}
if table_return.String != name {
return "", errors.New("Returned table is not the same as requested table")
}
return table_sql.String, nil
}
What license is the code released under?
I may be blind, but I can't it referenced anywhere.
The type is JSON type and accept NULL type.
When dump with this tool, the data will transfer the NULL to "" type.
When import, it make issue, because "" is wrong type.
Hello, it seems that InnoDB backup is having some problem. I didn't try MyISAM or anything else storage engine, but with my InnoDB database with Foreign Key constraint cannot be recovered with what I backup with this package. ;(
Hey,
currently the data is rendered after all tables have been retrieved.
This is a viable approach when working with a small database.
However using this library with a database of multiple 10s of GB this is no longer feasible since size of the dump will exceed the memory of the instance you are running the program.
Any plans to extend the functionality of your lib to tackle this issue?
When this is dumping, does it lock the database?
Does this library include the option of dumping all databases of a MySQL db server? Its CLI equivalent has --all-databases
flag which does what I need.
According to the example in the README, dumper works according to its mysql dsn input which requires dbname to be specified. Am I right?
Error dumping: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition' at line 1
hello,
I found this library that dump the mysql database, I was hopeful it was possible to use it for postgres or that there is a solution available,
so far it appears its not so.
So I am guessing is there any plan to make it supported or it looks like a more natural soluion for me to fork and create a postgresql version?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.