How to transfer from localHost to live but use the already existing database on the server?

Moving your sites

My recommendation would be to use the the duplicator plugin. Far and away the easiest method I’ve used to back-up, move, and restore sites from local to production or from one host to another.

If the old site is WordPress – sounds like it is, you may want to consider creating a sub-domain and then using duplicator on the old site to back-up and then restore the old site to the new sub-domain.

mysite.com -> old.mysite.com

Then use duplicator to back-up your local dev site and then restore it to the location of the original site.

Connecting to the old DB

Once you have both sites on your host mysite.com and old.mysite.com you could change the settings in the wp-config.php of the new site (now mysite.com) to point to the db of the old site (old.mysite.com) like so:

// wp-config.php

define ( 'DB_NAME', 'olddbname' );
define ( 'DB_USER', 'olddbusername' );
define ( 'DB_PASSWORD', 'olddbpassword' );
define ( 'DB_HOST', 'old.mysite.com' ); 

In fact you could probably just copy the DB definitions from the wp-config of old.mysite.com into the wp-config of the mysite.com.

  • I’d comment out the db definitions present for mysite.com.

Can you clarify what you want to accomplish by doing this?
The problem with pointing the new site to the old db is that it will also use the old site theme etc. A sum zero really. If your just trying to get the posts and pages from the old site to the new, I’d use the export/import tools that come packaged with WordPress. There are also syndicate plugins (FeedPress is my preferred one) that seem to be more robust than the WordPress import/export tools.