Tag Archives: Database

Rails database.yml user vs username

In the database.yml file that Rails uses to define the database connection details for each environment you need to make sure it says username and not just user. If you use user than it will most likely work on your local machine, making you believe there is not issue.

BAD:

development:
  user: root
  password: root

 

GOOD:

development:
  username: root
  password: root

What collation/encoding is my database using?

Very simple.

USE `your_database`
show variables like "character_set_database";
show variables like "collation_database";

Delete all tables in a MySQL database

I was looking for a script to delete all tables in a MySQL database without having to drop the database.

mysqldump -u [username] -p --add-drop-table [database] | grep ^DROP | mysql -u [username] -p

/cc @davelens

Let mysqldump help you!

I used to dump mysql data using PHPMyAdmin. People should get kicked in the nuts for doing that.

Dumping a (remote) database:

mysqldump -uroot -proot –host=mysql.openminds.be my_database > Desktop/dump.sql

Restoring a database:

mysql -uroot -proot my_database < Desktop/dump.sql

Disclaimer: I know that it’s stupid to set the password in the command, but this is just for the example. /cc @adeepersilence