This may be an insanely easy thing to do, but I'm completely lost. I'm working off of a server which is currently hosting two websites: the older site, and the newer wordpress site. The default database on the server is currently for the older site and I'm trying to figure out how to switch it so that the wordpress database is the default, and that site displays instead of the old one. I have access to the server and can login through mysql, but am not sure where to go from there. Any help?
-
mySQL doesn't have a concept of a default database. You connect to mySQL and have to select a database in order to make a query. If you want to make a site show up instead of the other, that is most likely a web server configuration issue - but that needs a lot more information to be answered, and possibly belongs on http://serverfault.com rather than here – Pekka Oct 05 '11 at 08:40
1 Answers
To set a default database on MySQL, you need to add the following lines to your /etc/mysql/my.cnf
:
#Setting the default database
[client]
database = the_desired_database_name
Or to keep things more organized you can create a new file at /etc/mysql/conf.d/
with a .cnf
extension (it will be loaded the same way my.cnf does, when the server is started). In my case I created the following /etc/mysql/conf.d/default_database.cnf
and added the content I showed you before.
Don't forget to restart Apache after creating the new
.cfn
file or editing yourmy.cfn
.
Testing: now when you start MySQL on a terminal, your default database should be already selected (no 'USE' statement required at first).
$ mysql -u username -p
$ show tables;
And about your wordpress more specific situation, you said:
I'm trying to figure out how to switch it so that the wordpress database is the default, and that site displays instead of the old one. [...]
As far as I can see, there is no relation between the default database and the default displayed website. Changing the default database will not make your new website being served by default to your visitors.
If it applies to you, try to change the database your wordpress website is using by editing the wp_config.php
. Or maybe change your /www root directory to the location of your new site.
Hope it helps.

- 10,002
- 11
- 54
- 83