我在linux下赋予全体用户的全限一般这样进行:#mysql -uroot -p
Enter password:这里输入密码
mysql>use mysql;
mysql>grant all on *.* to root@'%' identified by 'password' with grant option;
mysql>exit;但是现在我想用一个脚本实现同样的功能,应该如何实现?
就比如为用户root添加密码可以用mysqladmin -u root password 'password',这样就可以在脚本里面用不知道修改权限有没有这样的命令?或者应该利用什么其他方法通过脚本来执行

解决方案 »

  1.   

    mysql -uroot -pxxxx -e"grant all on *.* to root@'%' identified by 'password' with grant option"
      

  2.   

    可以使用楼上的方法mysq -e 参数来执行SQL语句
    [code=BatchFile]C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -p123 test -e "select count(*) from t1;select count(*) from t2;"
    +----------+
    | count(*) |
    +----------+
    |   100000 |
    +----------+
    +----------+
    | count(*) |
    +----------+
    |       11 |
    +----------+C:\Program Files\MySQL\MySQL Server 5.1\bin>[/code]
      

  3.   

    或者用 mysqlmanager --add-user C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlmanager -uroot -p123 --add-user testaWARNING: This program is deprecated and will be removed in 6.0.[3248/0] [09/09/17 16:51:38] [INFO] IM: started.
    [3248/0] [09/09/17 16:51:38] [INFO] Loading config file 'C:\Program Files\MySQL\
    MySQL Server 5.1\bin\my.ini'...
    Error: password file (C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqlmanager.p
    asswd) does not exist.
    [3248/0] [09/09/17 16:51:38] [INFO] IM: finished.C:\Program Files\MySQL\MySQL Server 5.1\bin>