Skip to content

Instantly share code, notes, and snippets.

@rafaelfoster
Last active January 2, 2016 20:29
Show Gist options
  • Save rafaelfoster/8357293 to your computer and use it in GitHub Desktop.
Save rafaelfoster/8357293 to your computer and use it in GitHub Desktop.
Mysql Braimstorm
DATABASE="DATABASE"
USER="username"
PASSWD="password"
mysql -u $USER -p$PASSWD $DATABASE -e "show tables" |while read dbtable
do
mysql $DATABASE -e "ALTER TABLE $DATABASE.$dbtable ENGINE=InnoDB"
echo "Convertendo tabela: $dbtable"
done
-- Show Databases Size in GB
SELECT table_schema AS "Database name",
SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)"
FROM information_schema.TABLES GROUP BY table_schema;
-- Show Storage engine
SHOW VARIABLES LIKE 'storage_engine';
---[ User Management ]-------
-- Create user
CREATE USER 'user'@'[hostname/remote]' IDENTIFIED BY ['password' / PASSWORD 'hash'];
-- Grant privileges to user
GRANT PERMISSIONS ON base.table TO 'user'@'host';
FLUSH PRIVILEGES;
-- Set user password
SET PASSWORD FOR 'user'@'host' = PASSWORD('plain text pass');
-- Dump Mysql and selecting which tables to backup
DBTODUMP=mydb
TBLIST=`mysql -u... -p... -AN -e"select group_concat(table_name separator ' ') from information_schema.tables where table_schema='${DBTODUMP}' and table_name not in ('t1','t2','t3')"`
mysqldump -u... -p... ${DBTODUMP} ${TBLIST} > zabbix_mysql_tables.sql
#!/bin/bash
mysql -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from user;" mysql | mysql | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
# Refer: http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/
cat /proc/$(pgrep mysqld$)/limits
# vi /etc/sysctl.conf
fs.file-max = 100000
systemctl restart mariadb.service
cat /proc/$(pgrep mysqld$)/limits
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
# Configuration name server generated for [email protected] at 2014-11-05 18:06:36
[mysql]
# CLIENT #
port = 3306
#socket = /var/data/mysql.sock
[mysqld]
open_files_limit = 65535
# GENERAL #
server-id = 2
user = mysql
default-storage-engine = InnoDB
#socket = /var/data/mysql.sock
pid-file = /var/data/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 512M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /var/data/
# BINARY LOGGING #
log-bin = /var/data/mysql-bin
binlog_format = MIXED
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 128
#open_files_limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
tmpdir = /var/mysqltmpfs
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 0
innodb-buffer-pool-size = 6G
innodb_data_file_path = ibdata1:400G
# LOGGING #
log-error = /var/data/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/data/mysql-slow.log
[mysqld_safe]
open_files_limit = 65535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment