In MySQL, you can do
RENAME DATABASE mysql TO newDbName;
In your code, you can just change the query in the FROM
statement to your new database and table.
Or, if you were trying to start with a blank slate, then, after creating the new database, run the following:
mysqldump -u user -ppass -d olddb | mysql -u user -ppass -D newdb
which will copy your old schema to the new db.