使用Java在mysql中创建用户 [英] creating user in mysql using java

查看:326
本文介绍了使用Java在mysql中创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以root用户身份登录后,在 MySQL 命令行客户端中,输入:

In MySQL command line client after logging in as root, I typed:

connect mydb;
grant all privileges on mydb.* to 'admin'@'localhost' identified by 'pass';

现在在 Java 中, 我使用驱动程序的admin userid成功连接到数据库.

Now within Java, I succesfully connect to the db using the admin userid using drivers.

 Statement put=connect.createStatement();

 //**WORKS succesfully**
 put.execute("insert into mydb.emp values(100,joe)");   

 //**does NOT work**
 put.execute("grant all privileges on mydb.* to 'john'@'localhost' identified by 'pass'"); 

为什么插入命令有效,但授予命令却无法通过Java起作用?

Why does an insert command work but grant command never work through Java?

请帮助.

推荐答案

put.execute(MySQL query) 

在这里您只能执行MySQL查询,但

in here you can execute only MySQL query but

grant all privileges on mydb.* to 'admin'@'localhost' identified by 'pass';

这不是MySQL查询,它只是MySQL的命令.

Not a MySQL query it is just a command for MySQL.

这篇关于使用Java在mysql中创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆