简体   繁体   English

在PhpMyAdmin上使用SQL创建新用户

[英]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. 我在服务器上运行PHPmyAdmin,SQL和Apache。 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 注意* LOCALHOST是我的联系方式,此代码仅是示例

Use use ' not ' in your query. 在查询中使用use'not'。

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. 仅刷新用户权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM