Posts Tagged ‘MySQL’

Importing a SQL file directly from Command Line for MySQL

October 18th, 2011

I am writing this on the train, so I’ll be relatively quick.

It’s been a while since I wrote my import sql file via command line post and thought I’d post the updated version which I now use.

It is possible to execute an SQL file without logging into the mysql client first. Previously, I used login to mysql and use the source command to execute commands from an SQL text file.

Now, I execute it all straight from bash or windows shell without having to login to the MySQL client.

To import an SQL file by passing it as if it were an arguement, you need to use the < sign. So for example, say that I wanted to import an external database from production and wanted to import it into my development environment, I can do so by doing the following:

» Read more: Importing a SQL file directly from Command Line for MySQL

How to fix phpmyadmin error: “Connection for controluser as defined in your configuration failed”

January 3rd, 2011

“Connection for controluser as defined in your configuration failed” It’s one of those small, annoying messages that appear out of the way on your screen, but still catches your eye once in a while especially when you’re deep in thought about how to building a multi-join query in the SQL tab of phpmyadmin.

Well, it annoyed me today so much that I finally decided to do something about it and finally take a look. I opened up the PHPMyAdmin config file located at /etc/phpmyadmin/config-db.php  on Ubuntu Maverick Meerkat. There’s a default username and password in $dbuser and $dbpass variables.

Now my knee jerk reaction to this would have been “no problem I’ll just change that to my root username and password.” which will work by the way, but I decided against it since the control user for PHPMyAdmin did not really need to have access to all the other databases in my local cluster.

» Read more: How to fix phpmyadmin error: “Connection for controluser as defined in your configuration failed”

Unit testing with Live Databases and/or How do I use Mock Objects?

November 30th, 2010

This is another live coding note. I’ve found my rhythm with TDD and currently bashing away at some unit tests for the Models and Service layers for a project I’m working on.

In tonights post, I’m going to write about how I get around with Unit Testing live databases.

Unit Testing with Live Databases

For my unit tests, I’m currently working with a live test database since I don’t fully understand the “power” of mock objects. If you have any links out there that’s worth noting, please be a friend and “link me”. I’m not going to pretend that I know everything and anything about Web Development. I know a lot, but the one thing that I do know is that I don’t know everything.

Mock Objects. WTF are you?

One thing which is mostly a mystery to me is the concept and practical application of Mock Objects in Unit testing. I’ve read several articles on Mock objects, but some of them delve into how to create Mock Objects rather than practical usage for mock objects in a live development setting. What problem exactly are mock objects trying to solve?

I get that it replaces other objects that the current class your testing will collaborate with, but I’m guessing that this is due to not having a setup like I currently have where I have the extra application code which easily gives me access to the db resource so that I can just as easily do this within my unit test as it would with mock objects… maybe? I’m confused.

» Read more: Unit testing with Live Databases and/or How do I use Mock Objects?

MySQL Funny/Strange Characters replacing apostrophes after import

May 26th, 2009

Our client contact from a Web Design Company we develop web applications and business websites for rang us late yesterday with a problem they had encountered. They were migrating a database from one MySQL database server to another and noticed that question marks and other strange characters such as aeons or blackbox question marks are appearing everywhere.

How did this happen?
This happens because the test server’s character set (utf8) did not match the production servers client (which is set to latin1 by default) this is what does all the importing and since UTF8 Unicode has some characters that are missing or are different to latin1, they are replaced with a question mark.

» Read more: MySQL Funny/Strange Characters replacing apostrophes after import

Importing SQL dumps into MySQL through Command line

March 11th, 2008

UPDATE 2011: I’ve created another blog post on this subject which describes an easier way of importing SQL files directly from the command line with MySQL. The method on the new blog post describes how to do it in one step directly from the command line. Check it out!

Perhaps it’s because I’ve been in maintenance mode for a little bit that I’ve forgotten how to import a SQL file generated by applications like mysqldump into an existing database, but earlier today while dumping existing data from DevScripts and trying to install it on our testing server, I drew a complete blank.

So I guess this is more a note for me and anyone else who has a tendency to forget nifty little tricks like this one.

A quick way to duplicate MySQL databases is to do the following:

» Read more: Importing SQL dumps into MySQL through Command line