How To: Use MySQL Connector/C++ to Connect to a MySQL Database in Windows

I got this working in Linux in about ten minutes, while the same thing in Windows took me closer to three hours… The difficulty I had was that I need to get this working on multiple machines which all get wiped and reset on each boot, so it had to be entirely stand-alone with everything necessary to build in the same project. And the difficulty with that is that Connector/C++ needs the boost library to compile, which I wasn’t too keen on involving. In the end I couldn’t find a way around it and just threw the entire boost library into the same directory as the project as well as the libmysql.lib/dll and mysqlcppconn.lib libraries.

So now it works. It’s a little ugly, and the project folder comes in at 62MB, but it works. Really it’s not all that bad, if you just wanted to build and deploy something you’d end up with a couple of hundred KB executable plus a few MB of dlls. I guess I could go in and strip out some parts of the boost library which aren’t being used. But to be honest it’s been a long day and I’m sick of fighting with it, so I’ll leave that as an exercise for the reader.

Reminder / Info

  • This code is tested and working on Windows XP 32-Bit.
  • The project (i.e. download, at bottom of post) is for Microsoft Visual Studio 2008 Express
  • The version of the libs/headers included are:
    • libmysql.lib from MySQL server v1.5.36 32-Bit
    • boost library v1.45.0
    • mysqlcppconn.lib/dll from Connector/C++ v1.1.0 32-Bit
  • I really, really hate having to work with Windows.

Anyhoo – here’s the junk…

*** REALLY IMPORTANT: Build the following project in Release mode if you want it to work!! No, really. The libs and dll’s that the project uses have been built in Release mode and you can’t mix n’ match. ***

Download of Visual Studio 2008 Express project including all necessary headers/libs/dlls (i.e. it’s ready to go – and 12MB): MySQL-Connector-Test.zip

Credits: Thanks to TidyTutorials for the guide that got me started.

How To: Disable All WordPress Plugins from the Database

I added a couple of WordPress plugins the other day to tack on a little bit of extended functionality to the site, but things went badly, and some bizarre interactions between plugins meant that I couldn’t log in to the WordPress administration interface – it would just throw me back to the main site without even having the option to log in… As such, I couldn’t disable the plugins (because you need to be in the administration interface to do that!), so what the heck to do?

You might think to ssh in to the box and remove the plugins from the …/wp-content/plugins/ folder to disable them (as I did) – only this won’t work. What we really need to do is disable the plugins directly from the database – and luckily for us it’s a pretty simple process as long as we can ssh into the box!

Note: If you dont’ have ssh access to your server, you could always take the phpMyAdmin route to achieve the same goal through a web interface, but if the problem you have is related to being redirected all the time (like mine was) then the direct DB access way is really the only way to go!

Gaining SSH Access

If you’re running linux you’ve already got a ssh client built in, if you’re on Windows then you’ll probably want to get yourself a copy of PuTTY or such.

Assuming the IP address of your server is 1.2.3.4, then you can ssh to the box with:

In the above command the switch is “minus lower-case-L”, not “minus pipe-symbol” or anything, and if you’ve changed your ssh port away from the default of 22, then you can just add the switch -p , so if my ssh daemon was running on port 2233, and I wanted to log in as the user bob, I’d use:

Connect to MySQL

Once you’ve got a ssh connection to the server, the next thing you’ll want to do is connect to your database, with the following command:

So if I had a MySQL administrator called dbAdmin I’d use:

The -p switch on the end will prompt you to enter the password for your MySQL admin user account – don’t worry if you’ve forgotten the credentials you should use – they’ll be in your WordPress wp-config.php file, which is usually located in your www or htdocs root folder (on Linux this is usually /var/www).

Quick Tip: By placing your wp-config.php file in the web root it’s possible for it to be accessed by malicious types, but you don’t have to place it here! You can, in fact, move the file one level up so that it’s outside of the web-root and WordPress will still be able to find it, but scoundrels won’t! So if you’re running WordPress with all your files in /var/www/ just move the wp-config.php file up to /var/ and it’ll still work and be safer! You can do this from the ssh terminal with:

Manipulate the Database

Once you’ve got administrator access to MySQL you need to connect to your database (again, the database name will be in your wp-config.php file), so if we’d called our database myWebDB then we could connect to it through the MySQL command line interface with:

Once this has connected successfully, all you have to do to disable all plugins is issue the following command:

That’s it! Attempt to access your site! Any plugins which were causing mayhem will now be disabled, and you can then add them back one-by-one until you find the combination that’s stuffing things up!

Cheers!

Props: Many thanks to Jeff Star of PerishablePress for his article Quickly Disable or Enable All WordPress Plugins via the Database which saved my bacon, and prompted me to write this quick guide.
Flattr this