How do I assign a new role to all the existing accounts on the site? I have more than 300 users in my site. I want to assigned them a new role I just created.

How do I achieve this?
One option would be to do it via the GUI (admin/people) where you can select all the shown users with the uppermost checkbox and then under 'update options' add the role you want. If it's a one time thing for ~300 users then this is probably the quickest way to handle it.

For a programmatic approach the user_multiple_role_edit() function can be used. You need to pass the user id-s as an array, the operation and role id to the function and it'll do the rest for you. You can get the role id by checking the edit link of the wanted role via the GUI (admin/people/permissions/roles).

To get all the user id-s and assign them the role you could use the following example (modify where needed):

$result = db_query('SELECT uid FROM {users}');
$uids = array();
foreach ($result as $record) {
  if ($record-&gt;uid == 0) continue;
  $uids[] = $record-&gt;uid;
}
user_multiple_role_edit($uids, 'add_role', 4);