I setup the database on a dedicated server owned by myself, and I will build another website hosted by shared hosting. This website need to access and manage the database on the dedicated server, now how to do this?
You need to add a remote user to the database. If you have shell access, you would do this via a GRANT query. http://dev.mysql.com/doc/refman/5.0/en/grant.html You should limit access to the specific IP of the server accessing it. Do not do a * for the host. You may also have to open port 3306 if the server has a firewall. Again, only open it to the IP of the server accessing it, if possible.
instead of using localhost in your code just give the ip of the dedicated server where you create the database along with the login details. Also make sure you allow the website IP to access the DB.