Jack Henry
Jack Henry

Reputation: 302

Creating a new user with SQL on PhpMyAdmin

For a school project we have to develop a simple database that allows different users to have certain privileges over the database. Anyway I have been struggling with the creation part, we were giving an example of code that can be used to create users and assign them to a database, however, it is not working.

 SELECT Host, User from mysql.user;

CREATE USER ‘David’ @‘localhost’ IDENTIFIED BY ‘password’;
SELECT Host, User from mysql.user;
Show databases;
Create database mydatabase;
Use mydatabase;
grant all on mydatabase.*to ‘David’ @‘localhost’;
set password for ‘David’ @‘localhost’ = password (‘newpassword’);

I do not know what is going on and how this actually works. I have PHPmyAdmin, SQL and Apache running on the server. Sorry if this question seems vague (or too simple )but it has been bothering me for a few hours now. Is it a mistake in the code?

NOTE* LOCALHOST is my connection and this code is just an example

Upvotes: 0

Views: 8044

Answers (1)

Leonardo
Leonardo

Reputation: 801

Use use ' not ‘ in your query.

SELECT Host, User from mysql.user;
CREATE USER 'David'@'localhost' identified by 'password';
SELECT Host, User from mysql.user;
Show databases;
Create database mydatabase;
Use mydatabase;
grant all on mydatabase.* to 'David'@'localhost';
flush privileges;

The problem is the quotation mark and spaces. Why are you changing the password after you created the user? You don't need to do that. Only flush user privileges.

Upvotes: 2

Related Questions