我想知道是否可以在由mysql
执行的sql脚本中切换“连接”用户。我可以在mysql源代码的sql脚本中切换“连接”用户吗?
下面是我的目标的描述。也许,没有必要让用户和另一个解决方案给我我想要的。
我想写一个数据库创建脚本像这样:
create databse some_db;
create user [email protected] identified by 'pw';
grant all on u.* to u;
-- Here's where I want to switch the user, but *obviously* the
-- following command fails
connect [email protected]/pw;
-- Now, as new user, create the tables:
use some_db;
create table t (...
这个脚本然后将命令行称为像
$ mysql -u root -p"....." < create_db.sql
这是可能的,或者我必须离开脚本以切换连接的用户?
为什么要切换用户中间脚本?你从中得不到什么。 –
@Justin也许有一个用户具有CREATE DATABASE和GRANT权限,但没有CREATE TABLE,而另一个用户只具有CREATE TABLE。 – Shi
@Shi我站好了,有些害怕了。 –