Mysql

Reducing ibdata1 in mysql

/etc/mysql/my.cnf:
innodb_file_per_table

Dump all databases by calling:

/usr/bin/mysqldump --extended-insert --all-databases --add-drop-database --disable-keys --flush-privileges --quick --routines --triggers > all-databases.sql

Stop the MySQL server;
Rename or remove (in case you’ve already backed it up) the MySQL data directory and create an empty one with the same name and permissions;
Make the appropriate changes in my.cnf;
Re-initialize the database with the following command (replace the ‘mysqld‘ with the login of the user your MySQL server runs as) (10x, Påven):

sudo -u mysqld mysql_install_db

Start the MySQL server;
Get into the ‘mysql‘ console and type:

SET FOREIGN_KEY_CHECKS=0;
SOURCE all-databases.sql;
SET FOREIGN_KEY_CHECKS=1;

Restart the MySQL server. (10x, czaby)

At this point everything should be fine and you can test it by starting again the services that use MySQL.

source

By WladyX on 23 January, 2012 | Mysql | A comment?

Strange character appearances in old posts (after db restore)

wp-config.php:
define('DB_CHARSET', 'utf8');

source

By WladyX on 29 December, 2011 | Mysql, Wordpress | A comment?

Export the privileges from MySQL and then import to a new server

.bashrc:
mygrants()
{
mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
) AS query FROM mysql.user" | \
mysql $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
}

mygrants --host=prod-db1 --user=admin --password=secret | grep rails_admin | mysql --host=staging-db1 --user=admin --password=secret
mygrants --password=xxx> /mysql.grant

source

By WladyX on | Mysql, Scripts | A comment?

DBeaver – free universal database tool

Supported (tested) databases:

  • MySQL
  • Oracle
  • PostgreSQL
  • IBM DB2
  • Microsoft SQL Server
  • Sybase
  • ODBC
  • Java DB (Derby)
  • Firebird (Interbase)
  • HSQLDB
  • SQLite
  • Mimer
  • H2
  • IBM Informix
  • SAP MAX DB
  • Cache
  • Ingres
  • Linter
  • Any JDBC compliant data source

download

By WladyX on 29 September, 2011 | Cool Apps, Mysql | A comment?

Wildcard – Grant Permissions To A Set Of Databases Matching A Pattern In MysQL

GRANT ALL PRIVILEGES ON `database_%` . * TO 'user'@'localhost' WITH GRANT OPTION ;

By WladyX on 22 July, 2011 | Mysql | A comment?

Duplicate mysql database

$ mysqldump -u root -p dbname >~/db_name.sql

$ mysql -u root -pmypassword
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 812
Server version: 5.1.20-beta-log FreeBSD port: mysql-server-5.1.20

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> create database dbname_copy
mysql> use dbname_copy
mysql> source ~/db_name.sql

source

By WladyX on 25 November, 2010 | Mysql | A comment?

Using mysqldump to Back Up Your MySQL Database

mysqldump -u root -p --all-databases > backup092210.sql

source

By WladyX on 30 September, 2010 | Mysql | A comment?

Useful Mysql Commands

By WladyX on 6 November, 2009 | General, Mysql | A comment?

iRedMail: Build A Full-Featured Mail Server With LDAP, Postfix, RoundCube, Dovecot, ClamAV, DKIM, SPF On CentOS 5.x

By WladyX on 15 April, 2009 | General, Mail, Mysql, Scripts | A comment?

Convert WordPress database from Latin1 to UTF-8

$ mysqldump –default-character-set=latin1 –databases wordpress > m.sql

$ replace “CHARSET=latin1″ “CHARSET=utf8″ \
“SET NAMES latin1″ “SET NAMES utf8″ < m.sql > m2.sql

$ mysql < m2.sql

wp-config.php:
define(‘DB_CHARSET’, ‘utf8′);
define(‘DB_COLLATE’, ”);

atppp’s Blog » Convert WordPress database from Latin1 to UTF-8

By WladyX on 30 June, 2008 | Mysql, Wordpress | A comment?