Howto transfer a single mysql table between several deployment stages

Posted Over 11 years ago.

shell-for stage_1 shell-for stage_2 Get the stage1 and stage2 MySQL credentials: cat /opt/www/the_stage.host.tld/current/config/database.yml cat config/database.yml # should do it Dump the table to a path reachable...

...by the stage2 user (e.g. home): mysqldump -h mysql1 -u stage_1_user -p stage_1_database table_name > ~/table_name_dump.mysql # Select certain records using --where "some_id > 666"

Mysql/Mysql2 agnostic database.yml

Posted Almost 12 years ago by Tobias Kraze.

If you upgrade to the mysql2 gem, you will run into the problem that the server's database.yml (which is usually not under version control) needs to change exactly on...

You can however make your database.yml work for mysql and mysql2 at the same time. Simpy do this production: adapter: <%= defined?(Mysql2) ? 'mysql2' : 'mysql...

MySQL Server and UTF-8 Defaults

Posted Over 13 years ago.

Unless all MySQL server defaults are set to UTF-8, mysqldump encodes UTF-8 characters incorrectly and only outputs correct UTF-8 when you switch to Latin 1 (!). Also you...

...for each new database. To prevent this, make sure your /etc/mysql/my.cnf looks like this: [mysqld] default-character-set = utf8mb4 collation-server = utf8mb4_unicode_ci [mysql] default-character-set=utf8mb4

Installing old versions of mysql2 on Ubuntu 20.04+

Posted Over 3 years ago by Tobias Kraze.

On some of our older projects, we use the mysql2 gem. Unfortunately, versions 0.2.x (required for Rails 2.3) and versions 0.3.x (required for Rails 3.2) can no longer...

...when compiling the native extension, or a segfaults when using it. For Rails 4.2, mysql2 version 0.4.10 seems to work okay. If you still have issues, upgrade to 0.5.x...

Fix error: Missing the mysql2 gem

Posted Over 11 years ago by Henning Koch.

So you got this error, even though your Gemfile bundles mysql2: !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' or Please install the mysql adapter: `gem install...

...activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) The reason for this confusing error message is probably that your Gemfile says mysql2, but your...

Dumping and importing from/to MySQL in an UTF-8 safe way

Posted Over 13 years ago by Henning Koch.

...when importing. Dumping safely # Do not do this, since it might screw up encoding mysqldump -uroot -p database > utf8.dump # this is bad Better do: mysqldump -uroot -p database -r utf8.dump

...Note that when your MySQL server is not set to UTF-8 you need to do mysqldump --default-character-set=latin1 (!) to get a correctly encoded dump. In that case...

MySQL 5.1: Switch to InnoDB Plugin for better performance

Posted Almost 12 years ago by Tobias Kraze.

MySQL version 5.1 comes with an alternative, faster InnoDB implementation (called "InnoDB Plugin"). Switching is easy: Stop your mysqld with sudo stop mysql Add the following lines to your /etc/mysql/my.cnf...

...under the [mysqld] section ignore-builtin-innodb plugin-load=innodb=ha_innodb_plugin.so Start your mysqld with sudo start mysql The file format has not changed, your tables should survive this.

Store MySQL passwords for development

Posted About 6 years ago by Florian Heinle.

...hosts non-critical development data and only you have access to, you can store MySQL's root password in your home directory so you can use mysql commands without prompt...

user=root password=YOURMYSQLROOTPASSWORDHERE EOF Now you should be able to just type mysql and be logged in as MySQL's root user. This works for different MySQL commands...

Mysql::Error: BLOB/TEXT column can't have a default value

Posted About 6 years ago by Emanuel.
stackoverflow.com

mysql> SELECT @@global.version; +------------------+ | @@global.version | +------------------+ | 5.6.30 | +------------------+ 1 row in set (0,00 sec) MySQL 5.6 Reference Manual says "BLOB and TEXT columns cannot have DEFAULT values". If you want to run...

...and stash you changes in the migration files. 2. Temporally change the sql mode mysql> SELECT @@global.sql_mode; +--------------------------------------------+ | @@global.sql_mode | +--------------------------------------------+ | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | +--------------------------------------------+

Change the MySQL default character set on Amazon Relational Database Service (RDS)

Posted Over 12 years ago by Kim Klotz.

Look here for informations how you can show the MySQL default character set. At first you need the Amazon RDS Command Line Toolkit download and unzip the Amazon RDS Command...

After that you can create a new parameter group /home/foobar/Downloads/RDSCli-1.4.007/bin/rds-create-db-parameter-group utf8 -f mysql5.1 -d "default parameter with utf8" --aws-credential-file ./aws-credential.txt --region eu-west-1

MySQL: How to clone a database

Posted Over 12 years ago by Arne Hartherz.

...and their data, under a new name. Make a dump of your source database: mysqldump -uroot -p my_project -r my_project.sql Or, if you only want to dump the database...

...s table structure (schema) without any contents: mysqldump -uroot -p my_project -r my_project.sql --no-data Open up a MySQL shell: mysql -uroot -p From the MySQL shell, create a...

Install MySQL 5.6 in Ubuntu 16.04

Posted Almost 8 years ago by Tobias Kraze.

...itself did not work for me. Uninstall everything related to MySQL 5.7 with apt remove mysql-client mysql-server libmysqlclient-dev mysql-common Check if you removed everything using

...MySQL 5.6" and "Ubuntu Wily" (assuming Xenial is not yet provided) Run apt-cache policy mysql-server If this shows a 5.6 version, continue. If not, check your /etc/apt/sources.list.d/mysql.list. It...

MySQL replication how-to

Posted Over 13 years ago by Arne Hartherz.

The result might look like this: +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 1219 | | | +------------------+----------+--------------+------------------+ Dump the database (in a new terminal): mysqldump -uroot -p -r...

...HOST='127.0.0.1', MASTER_PORT=3307, MASTER_USER='replicator', MASTER_PASSWORD='some_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1219; MASTER_HOST and MASTER_PORT are set to...

MySQL 5.7.5 enables `ONLY_FULL_GROUP_BY` mode per default

Posted Almost 7 years ago by Natalie Zeumann.

When using GROUP BY, MySQL now complains if the SELECT includes columns which are not part of the GROUP BY. Reason: There could be multiple values for those columns per...

Also see our card on SQL compatibility modes. Install MySQL 5.6 in parallel, using mysql-sandbox Use MariaDB 10.x What TRADITIONAL changes MySQL 5.7 standard TRADITIONAL

How to change MySQL's data directory

Posted About 13 years ago by Arne Hartherz.

Stop MySQL: sudo service mysql stop Move (or copy) your mysql directory. If you want /mnt/mysql to be the new directory, do it like this:

.../var/lib/mysql /mnt/ Open your MySQL configuration (sudo vim /etc/mysql/my.cnf) and change the datadir value to your new path (e.g. /mnt/mysql) Modify your AppArmor configuration: sudo vim /etc/apparmor.d/usr.sbin.mysqld Change/copy the lines...

How to enable MySQL query logging

Posted Almost 12 years ago by Arne Hartherz.

This will make MySQL log all received queries so you can see for yourself what happens on the database level. Don't switch this on for production machines!

sudo vim /etc/mysql/my.cnf In the [mysqld] section, add: log=/var/log/mysql.log Restart your MySQL daemon. On Ubuntu: sudo service mysql restart Note that your MySQL performance will suffer. But when...

Properly sanitizing column names for MySQL

Posted About 13 years ago by Thomas Eisenbarth.

...COUNT(DISTINCT #{field}) AS count") end Although the given variable is sanitized here, the MySQLAdapter's (and probably other adapters as well) method for this is insufficient as it only...

...query will look like this: SELECT COUNT(DISTINCT `id); DELETE FROM users; -- `) AS count; MySQL will complain about a missing column '`id); DELETE FROM users; -- `' which is safe.

MySQL: How to dump single tables instead of a complete database

Posted Over 7 years ago by Emanuel.

...data. Dumping single tables makes sense if a complete dump would be to big. mysqldump -u deploy_user -p application_production table1 table2 table2 > table1_table2_table2.sql.dump Hint: If a table has...

...be more handy. Further reading: - How to load only a subset of a massive MySQL dump - How to import production database dump to staging (or the other way...

MySQL/MariaDB: Hide all sleeping processes in processlist

Posted Over 8 years ago by Thomas Eisenbarth.

If you have many connections to your MySQL or MariaDB (as we have) you might want to filter the list you see when running a SHOW PROCESSLIST. To hide all...

There is an more advanced way by querying the information_schema database: Show MySQL process list without sleeping connections

UTF-8ify an existing MySQL database

Posted Over 13 years ago by Henning Koch.

ALTER DATABASE database_name CHARACTER SET "utf8"; ALTER DATABASE database_name COLLATE "utf8_unicode_ci"; After that, for...

MySQL: How to create columns like "bigint" or "longtext" in Rails migrations, and what :limit means for column migrations

Posted About 11 years ago by Arne Hartherz.
ariejan.net

...create an int column, which is smaller than a bigint. These are values for MySQL. At least on PostgreSQL you can just use bigint instead of integer: create_table :example...

How FriendFeed uses MySQL to store schema-less data - Bret Taylor's blog

Posted Over 14 years ago by Lexy.
bret.appspot.com

...some deliberation, we decided to implement a "schema-less" storage system on top of MySQL rather than use a completely new storage system. This post attempts to describe the high...

NoSQL with MySQL in Ruby - Friendly

Posted Over 14 years ago by Lexy.
friendlyorm.com

Store schema-less data in MySQL...

mysql-master-master - Google Code

Posted About 15 years ago by Lexy.
code.google.com

MMM (MySQL Master-Master Replication Manager) is a set of flexible scripts to perform monitoring/failover and management of MySQL Master-Master replication configurations (with only one node writable at any...