15
Apr
2020

Bulk Export

15 Apr 2020
SQL-Insert-Statements-Bulk-100per.sql.groovy SEP = ", " QUOTE = "\'" NEWLINE = System.getProperty("line.separator") KEYWORDS_LOWERCASE = com.intellij.database.util.DbSqlUtil.areKeywordsLowerCase(PROJECT) KW_INSERT_INTO = KEYWORDS_LOWERCASE ? "insert into " : "INSERT INTO " KW_VALUES = KEYWORDS_LOWERCASE ? "values" : "VALUES" KW_NULL = KEYWORDS_LOWERCASE ? "null" : "NULL" OUT.append(KW_INSERT_INTO) if (TABLE == null) OUT.append("post") else OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName()) OUT.append(" (") COLUMNS.eachWithIndex { column, idx -> OUT.append(column.name()).append(idx != COLUMNS.size() - 1 ? SEP : "") } OUT.append(")").append(NEWLINE).append(KW_VALUES) def record(columns, dataRow, close) { OUT.append(NEWLINE).append("(") columns.eachWithIndex { column, idx -> def value = dataRow.value(column) def skipQuote = value.toString().isNumber() || value == null def stringValue = value != null ? FORMATTER.format(dataRow, column) : KW_NULL if (DIALECT.getDbms().isMysql()) stringValue = stringValue.replace("\\", "\\\\") OUT.append(skipQuote ? "": QUOTE).append(stringValue.replace(QUOTE, QUOTE + QUOTE)) .append(skipQuote ? "": QUOTE).append(idx != columns.size() - 1 ? SEP : "") } deliMeter = dataRow.last() || close ? ";" : "," OUT.append(")").append(deliMeter) } count = 0 def createInsert(columns, dataRow) { count++ if (count%100 == 0 && !dataRow.last()) { record(columns, dataRow, true) OUT.append(NEWLINE).append(KW_INSERT_INTO) if (TABLE == null) OUT.append("post") else OUT.append(TABLE.getParent().getName()).append(".").append(TABLE.getName()) OUT.append(" (") COLUMNS.eachWithIndex { column, idx -> OUT.append(column.name()).append(idx != COLUMNS.size() - 1 ? SEP : "") } OUT.append(")").append(NEWLINE).append(KW_VALUES) return } record(columns, dataRow, false) } ROWS.each { row -> createInsert(COLUMNS, row) }
8
May
2018

how to see open connections

08 May 2018
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE HOST LIKE '%192.168.0.0%';
25
Jan
2018

Fast create MySQL user and db with prevs

25 Jan 2018
CREATE USER 'fast'@'%' IDENTIFIED WITH mysql_native_password AS '***'; GRANT USAGE ON *.* TO 'fast'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; CREATE DATABASE IF NOT EXISTS `fast`; GRANT ALL PRIVILEGES ON `fast`.* TO 'fast'@'%'; GRANT ALL PRIVILEGES ON `fast\_%`.* TO 'fast'@'%';
15
Sep
2017

MySQL grep table

15 Sep 2017
Cut table from dump: sed -n -e '/CREATE TABLE.*`mytable`/,/CREATE TABLE/p' mysql.dump > mytable.dump