Change account settings in db
You want to modify a user_register variable and set it to 0.
You can set it in code:

variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);


by drush:

drush vset user_register 0


or directly in database (note that in variable table are stored serialized values):

UPDATE variable SET value = 's:1:"0";' WHERE name = 'user_register';


but this requires cleaning cache.

DELETE FROM cache_bootstrap WHERE cid = 'variables';