mysqldump all databases from XAMPP on Windows

A quick note to hopefully save others the time I’ve just wasted. If you want to dump out all your databases, perhaps in preparation for an upgrade to XAMPP as I’m about to try:

  1. Open up a command prompt (in Win 8+ type ‘Command’ and press <Enter> from the Start screen);
  2. Type:
    cd\xampp\mysql\bin

    (or wherever your myslq.exe is located)

  3. Type:
    mysqldump --user=root --password=myrootpwd --all-databases > backup.sql

Other options for this command can be found on the MySQL site.

Note that you are doing this from the Windows Command prompt – don’t get distracted, as I was, by running the MySQL command line tool. If you try and run mysqldump from the:

mysql>

prompt, you’ll get various syntax errors such as:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump...' at line 1

However, if running the MySQL command line tool is what has brought you to this post, you launch this by following steps 1 & 2 above and then typing:

mysql --user=root --password=myrootpwd

When executing commands at the:

mysql>

prompt, don’t forget that it allows you to enter multiple lines at once and that clicking <Enter> will just give you a new line unless you finish your line with a semi-colon – this will tell MySQl that you want to execute the command.

 

XAMPP (1.8.1) on Windows 8 – Apache not starting as Port 80 “in use by system”

I have recently upgraded to Windows 8 and installed XAMPP 1.8.1. On trying to start Apache using XAMPP Controller, I kept getting an error message saying that Apache could not be started because port 80 (the default port for Apache) was “in use by system”.

After a bit of searching around, one common solution, and the one that worked for me, was to turn off the “World Wide Web Publishing Service”, as follows:

  • Go to Control Panel > Administrative Tools > Services
  • Find “World Wide Web Publishing Service”
  • Right click and select “Stop”
  • Right click and select “Properties”, then change “Startup type” to “Manual”

If this doesn’t fix it, you can find out what is using port 80 as follows:

  • In a Command Prompt, run ‘netstat -ao > netstat.txt’ to write active connections and associated process IDs (PID) to a file (for me, there were too many to just view them in the command prompt)
  • Find the PID that is listening on port 80 (0.0.0.0:80) – for me, the PID was 4, which seems quite common
  • Open Task Manager (Ctrl + Shift + Esc), right click on the column headers, and then click PID to show the PID column. Sort by PID to find the process for the PID that you identified above.

Once you know the process that is causing the problem, a bit of Googling (other search providers are available) should help you fix it.

Resetting the root password/privileges for MySQL/PHPMyAdmin (XAMPP 1.7.3, MySQL 5.1.41)

We use XAMPP for our local development (on Windows), and I have a habit of messing around with the database and doing bad things by mistake, because it’s only for local development, so it doesn’t matter that much. It’s still annoying when I lock myself out of all my databases though!

While setting up a wordpress site locally for testing, I managed to remove the global privileges of the root user in PHPMyAdmin, thinking it was the user for the wordpress database. I did the usual thing of searching for solutions online, and after trying a few different things involving the command line and MySQL Workbench, I came across this Apache Friends forum thread: http://www.apachefriends.org/f/viewtopic.php?f=16&t=46832. The instructions boil down to the following:

  • Open mysql/resetroot.bat in a text editor
  • Add “–datadir=c:/xampp/mysql/data” into the “mysql\bin\mysqld.exe…” line (line 18), after “–no-defaults”. Change the datadir parameter to the path to your data directory – the one shown is the default.
  • Run resetroot.bat – this should reset the MySQL root password and privileges. You can then login to MySQL/PHPMyAdmin using the username root and no password. For security, you should set a password for the MySQL admin user in the XAMPP Security panel: http://localhost/security/