I am trying to create a db user and assigned him to the new database what already has been created using dbforge library:
$this->dbforge->create_database( $oData->db_name );
My question is:
My code to create a database and user:
$this->load->dbforge();
// create user
$this->db->query("CREATE USER '". $data->db_user ."'@'localhost' IDENTIFIED BY '". $data->db_password ."';");
// create database
$this->dbforge->create_database( $data->db_name );
The answer of my own qestion found a is:
What must do first - create user or create a database? -
How to assign user to current database and add grant privileges? - Following this code I created a new user, with grant privileges, which can access to all databases:
$db->query("CREATE USER '". $oData->db_user ."'@'localhost' IDENTIFIED BY '". $oData->db_password ."';"); $db->query("GRANT CREATE, ALTER, DELETE, INSERT, SELECT, DROP, UPDATE ON * . * TO '". $oData->db_user ."'@'localhost';");