mysql 中execute,executeQuery和executeUpdate之间的区别

如题所述

MySQL各种权限(共27个)(以下操作都是以root身份登陆进行grant授权,以p1@localhost身份登陆执行各种命令。)1.usage连接(登陆)权限,建立一个用户,就会自动授予其usage权限(默认授予)。mysql>grantusageon*.*to‘p1′@’localhost’identifiedby‘123′;该权限只能用于数据库登陆,不能执行任何操作;且usage权限不能被回收,也即REVOKE用户并不能删除用户。2.select必须有select的权限,才可以使用selecttablemysql>grantselectonpyt.*to‘p1′@’localhost’;mysql>select*fromshop;3.create必须有create的权限,才可以使用createtablemysql>grantcreateonpyt.*to‘p1′@’localhost’;4.createroutine必须具有createroutine的权限,才可以使用{create|alter|drop}{procedure|function}mysql>grantcreateroutineonpyt.*to‘p1′@’localhost’;当授予createroutine时,自动授予EXECUTE,ALTERROUTINE权限给它的创建者:mysql>showgrantsfor‘p1′@’localhost’;+—————————————————————————+Grantsforp1@localhost+————————————————————————–+|GRANTUSAGEON*.*TO‘p1′@’localhost’IDENTIFIEDBYPASSWORD‘*23AE809DDACAF96AF0FD78ED04B6A265E05AA257′||GRANTSELECT,CREATE,CREATEROUTINEON`pyt`.*TO‘p1′@’localhost’||GRANTEXECUTE,ALTERROUTINEONPROCEDURE`pyt`.`pro_shop1`TO‘p1′@’localhost’|+————————————————————————————-+5.createtemporarytables(注意这里是tables,不是table)必须有createtemporarytables的权限,才可以使用createtemporarytables.mysql>grantcreatetemporarytablesonpyt.*to‘p1′@’localhost’;[mysql@mydev~]$mysql-hlocalhost-up1-ppytmysql>createtemporarytablett1(idint);6.createview必须有createview的权限,才可以使用createviewmysql>grantcreateviewonpyt.*to‘p1′@’localhost’;mysql>createviewv_shopasselectpricefromshop;7.createuser要使用CREATEUSER,必须拥有mysql数据库的全局CREATEUSER权限,或拥有INSERT权限。mysql>grantcreateuseron*.*to‘p1′@’localhost’;或:mysql>grantinserton*.*top1@localhost;8.insert必须有insert的权限,才可以使用insertinto…..values….9.alter必须有alter的权限,才可以使用altertablealtertableshopmodifydealerchar(15);10.alterroutine必须具有alterroutine的权限,才可以使用{alter|drop}{procedure|function}mysql>grantalterroutineonpyt.*to‘p1′@’localhost‘;mysql>dropprocedurepro_shop;QueryOK,0rowsaffected(0.00sec)mysql>revokealterroutineonpyt.*from‘p1′@’localhost’;[mysql@mydev~]$mysql-hlocalhost-up1-ppytmysql>dropprocedurepro_shop;ERROR1370(42000):alterroutinecommanddeniedtouser‘p1′@’localhost’forroutine‘pyt.pro_shop’11.update必须有update的权限,才可以使用updatetablemysql>updateshopsetprice=3.5wherearticle=0001anddealer=’A';12.delete必须有delete的权限,才可以使用deletefrom….where….(删除表中的记录)13.drop必须有drop的权限,才可以使用dropdatabasedb_name;droptabletab_name;dropviewvi_name;dropindexin_name;14.showdatabase通过showdatabase只能看到你拥有的某些权限的数据库,除非你拥有全局SHOWDATABASES权限。对于p1@localhost用户来说,没有对mysql数据库的权限,所以以此身份登陆查询时,无法看到mysql数据库:mysql>showdatabases;+——————–+|Database|+——————–+|information_schema||pyt||test|+——————–+15.showview必须拥有showview权限,才能执行showcreateview。mysql>grantshowviewonpyt.*top1@localhost;mysql>showcreateviewv_shop;16.index必须拥有index权限,才能执行[create|drop]indexmysql>grantindexonpyt.*top1@localhost;mysql>createindexix_shoponshop(article);mysql>dropindexix_shoponshop;17.excute执行存在的Functions,Proceduresmysql>callpro_shop1(0001,@a);+———+|article|+———+|0001||0001|+———+mysql>select@a;+——+|@a|+——+|2|+——+18.locktables必须拥有locktables权限,才可以使用locktablesmysql>grantlocktablesonpyt.*top1@localhost;mysql>locktablesa1read;mysql>unlocktables;19.references有了REFERENCES权限,用户就可以将其它表的一个字段作为某一个表的外键约束。20.reload必须拥有reload权限,才可以执行flush[tables|logs|privileges]mysql>grantreloadonpyt.*top1@localhost;ERROR1221(HY000):IncorrectusageofDBGRANTandGLOBALPRIVILEGESmysql>grantreloadon*.*to‘p1′@’localhost’;QueryOK,0rowsaffected(0.00sec)mysql>flushtables;21.replicationclient拥有此权限可以查询masterserver、slaveserver状态。mysql>showmasterstatus;ERROR1227(42000):Accessdenied;youneedtheSUPER,REPLICATIONCLIENTprivilegeforthisoperationmysql>grantReplicationclienton*.*top1@localhost;或:mysql>grantsuperon*.*top1@localhost;mysql>showmasterstatus;+——————+———-+————–+——————+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|+——————+———-+————–+——————+|mysql-bin.000006|2111|||+——————+———-+————–+——————+mysql>showslavestatus;22.replicationslave拥有此权限可以查看从服务器,从主服务器读取二进制日志。mysql>showslavehosts;ERROR1227(42000):Accessdenied;youneedtheREPLICATIONSLAVEprivilegeforthisoperationmysql>showbinlogevents;ERROR1227(42000):Accessdenied;youneedtheREPLICATIONSLAVEprivilegeforthisoperationmysql>grantreplicationslaveon*.*top1@localhost;mysql>showslavehosts;Emptyset(0.00sec)mysql>showbinlogevents;+—————+——-+—————-+———–+————-+————–+|Log_name|Pos|Event_type|Server_id|End_log_pos|Info|+—————+——-+————–+———–+————-+—————+|mysql-bin.000005|4|Format_desc|1|98|Serverver:5.0.77-log,Binlogver:4||mysql-bin.000005|98|Query|1|197|use`mysql`;createtablea1(iint)engine=myisam|……………………………………23.Shutdown关闭MySQL:[mysql@mydev~]$mysqladminshutdown重新连接:[mysql@mydev~]$mysqlERROR2002(HY000):Can’tconnecttolocalMySQLserverthroughsocket‘/tmp/mysql.sock’(2)[mysql@mydev~]$cd/u01/mysql/bin[mysql@mydevbin]$./mysqld_safe&[mysql@mydevbin]$mysql24.grantoption拥有grantoption,就可以将自己拥有的权限授予其他用户(仅限于自己已经拥有的权限)mysql>grantGrantoptiononpyt.*top1@localhost;mysql>grantselectonpyt.*top2@localhost;25.file拥有file权限才可以执行select..intooutfile和loaddatainfile…操作,但是不要把file,process,super权限授予管理员以外的账号,这样存在严重的安全隐患。mysql>grantfileon*.*top1@localhost;mysql>loaddatainfile‘/home/mysql/pet.txt’intotablepet;26.super这个权限允许用户终止任何查询;修改全局变量的SET语句;使用CHANGEMASTER,PURGEMASTERLOGS。mysql>grantsuperon*.*top1@localhost;mysql>purgemasterlogsbefore‘mysql-bin.000006′;27.process通过这个权限,用户可以执行SHOWPROCESSLIST和KILL命令。默认情况下,每个用户都可以执行SHOWPROCESSLIST命令,但是只能查询本用户的进程。mysql>showprocesslist;+—-+——+———–+——+———+——+——-+——————+|Id|User|Host|db|Command|Time|State|Info|+—-+——+———–+——+———+——+——-+——————+|12|p1|localhost|pyt|Query|0|NULL|showprocesslist|+—-+——+———–+——+———+——+——-+——————+另外,管理权限(如super,process,file等)不能够指定某个数据库,on后面必须跟*.*mysql>grantsuperonpyt.*top1@localhost;ERROR1221(HY000):IncorrectusageofDBGRANTandGLOBALPRIVILEGESmysql>grantsuperon*.*top1@localhost;QueryOK,0rowsaffected(0.01sec)
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答