Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign an existing user to mysql databases

Tags:

mysql

I have successfully created multiple databases in phpMyAdmin. I would now like to assign an existing user + respective password to all of these new databases by running a script on the SQL tab.

Please can you confirm what script I need to run, or if there is an easier script which can be run via root access, please then confirm the root-command for this?

like image 468
user3383762 Avatar asked Mar 05 '14 13:03

user3383762


People also ask

How do I add an existing user to phpmyadmin?

Editing an existing user To edit an existing user, simply click the pencil icon to the right of that user in the User accounts page. You can then edit their global- and database-specific privileges, change their password, or even copy those privileges to a new user.

How do I add a user to a database?

Expand the database in which to create the new database user. Right-click the Security folder, point to New, and select User.... In the Database User - New dialog box, on the General page, select one of the following user types from the User type list: SQL user with login.


1 Answers

Use the grant permissions command.

If your database was call "newDatabase" and your user was name "newUser" the command to grant all privileges on all the tables contained within would be:

GRANT ALL PRIVILEGES ON `newDatabase`.* TO 'newUser'@'localhost';

This would restrict the user from access the database only from the localhost, to enable access from all host change localhost to '%'

You then need to refresh the privileges with the following command:

FLUSH PRIVILEGES;

EDIT:

To grant privileges to every database on the mysql server use the following command (notice the *.*):

GRANT ALL PRIVILEGES ON *.* TO 'newUser'@'localhost';
like image 50
Digital Fu Avatar answered Sep 22 '22 07:09

Digital Fu