Discuss / Python / 创建MySQL数据库的时候大坑

创建MySQL数据库的时候大坑

Topic source

新版的MySQL有变动,sql语句里面的: grant select, insert, update, delete on awesome.* to 'www-data'@'localhost' identified by 'www-data'; 会报错的。 解决方案: 先create 用户——>再grant给各种权限。 具体代码自己查MySQL语法。 这里一直报错我也是醉了。

#创建新用户

create user 'www-data'@'%' identified by 'www-data';

#创建数据库

drop database if exists awesome;

create database awesome;

#给新用户赋权限

grant select, insert, update, delete,create on awesome.* to 'www-data'@'localhost' identified by 'www-data';

赋权的时候 'www-data'@'localhost'; 就可以了,如果加上 identified by 'www-data' 依旧报错。

壮士别跑

#4 Created at ... [Delete] [Delete and Lock User]

不仅如此,创建用户时@后边跟的限制主机名也要一样,创建时限制主机是%,赋权时也要%,前边是localhost,赋权时也要localhost,否则也会报错

WillamKwai

#5 Created at ... [Delete] [Delete and Lock User]

MySQL8.0 后。赋权去掉identified by 'www-data'; 否则会报ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'develop''

Nilllis

#6 Created at ... [Delete] [Delete and Lock User]

https://stackoverflow.com/questions/50177216/how-to-grant-all-privileges-to-root-user-in-mysql-8-0

Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command. Use CREATE USER instead, followed by the GRANT statement:

mysql> CREATE USER `www-data`@'localhost' IDENTIFIED BY 'www-data';

mysql> GRANT ALL PRIVILEGES ON *.* to 'www-data'@'localhost' WITH GRANT OPTION

这样是吗


  • 1

Reply