Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create db and user mysql and set privileges php [closed]

Is there a way to create a new MySQL database, a new MySQL user and give the new user privileges on the new database all using PHP?

like image 815
user1218364 Avatar asked Mar 15 '12 13:03

user1218364


2 Answers

i will suggest you to use phpmyadmin.

you need to do steps:

  1. open phpmyadmin
  2. go to admin section
  3. hit on add user account
  4. put user name and password
  5. set privileges
  6. hit the [ go ]button

that's all see in action on youtube [ click here ]

in case if you want to know more about phpMyadmin go with official

but if there is any special reason to do so with php the here is the sql commend

CREATE USER 'tesrytss'@'%'//user name
IDENTIFIED VIA mysql_native_password USING '***';.//set pass
GRANT SELECT, INSERT, UPDATE, DELETE, FILE ON *.* TO 'tesrytss'@'%' // previlages and username and location
REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; //other requerment
like image 96
insCode Avatar answered Sep 28 '22 06:09

insCode


You could do something like this:

mysql_connect('localhost','user',password);
mysql_query("CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';");
mysql_query("GRANT ALL ON db1.* TO 'username'@'localhost'");
mysql_query("CREATE DATABASE newdatabase");
mysql_close();

You may look at the MySQL documentation on GRANT and CREATE USER

like image 42
Fabian Avatar answered Sep 28 '22 06:09

Fabian