在python中操作必须要创建与用户的连接,因此需要在数据库中创建这个用户并且授权,在使用代码:
grant all privileges on pymysql_demo.* to 'pymysql_2'@'localhost';
的过程中,出现了报错:
ERROR 1410 (42000): You are not allowed to create a user with GRANT
该报错的意思是不能用grant语句创建用户
所以需要在此前先创建用户,使用一下语句:
create user 'pymysql_2'@'localhost' identified by "mysql";
(其中'pymysql_2'为你自己为用户起的名字,'mysql'为连接用户的密码)
创建用户之后,可以在用grant语句授权
e.g.
(如果想查询当前数据库的用户,可使用本语句:
select user,host from mysql.user;
e.g.
)