grant2.test
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· TEST 代码 · 共 590 行 · 第 1/2 页
TEST
590 行
create user 'mysqltest_1a', 'mysqltest_2', 'mysqltest_3a';--error 1396rename user 'mysqltest_1a' to 'mysqltest_1b', 'mysqltest_2a' TO 'mysqltest_2b', 'mysqltest_3a' TO 'mysqltest_3b';drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';--error 1396drop user 'mysqltest_1b', 'mysqltest_2b', 'mysqltest_3b';## Obsolete syntax has been droppedcreate user 'mysqltest_2' identified by 'Mysqltest-2';--error 1064drop user 'mysqltest_2' identified by 'Mysqltest-2';drop user 'mysqltest_2';## Strange user namescreate user '%@b'@'b';show grants for '%@b'@'b';grant select on mysql.* to '%@b'@'b';show grants for '%@b'@'b';rename user '%@b'@'b' to '%@a'@'a';--error 1141show grants for '%@b'@'b';show grants for '%@a'@'a';drop user '%@a'@'a';## CREATE USER privilege is enough#create user mysqltest_2@localhost;grant create user on *.* to mysqltest_2@localhost;connect (user3,localhost,mysqltest_2,,);connection user3;--error 1142select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;create user mysqltest_A@'%';rename user mysqltest_A@'%' to mysqltest_B@'%';drop user mysqltest_B@'%';disconnect user3;connection default;drop user mysqltest_2@localhost;## INSERT/UPDATE/DELETE is ok toocreate user mysqltest_3@localhost;grant INSERT,DELETE,UPDATE on mysql.* to mysqltest_3@localhost;connect (user4,localhost,mysqltest_3,,);connection user4;show grants;--error 1142select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;insert into mysql.user set host='%', user='mysqltest_B';create user mysqltest_A@'%';rename user mysqltest_B@'%' to mysqltest_C@'%';drop user mysqltest_C@'%';drop user mysqltest_A@'%';disconnect user4;connection default;drop user mysqltest_3@localhost;## Bug #3309: Test IP addresses with netmaskset @@sql_mode='';create database mysqltest_1;create table mysqltest_1.t1 (i int);insert into mysqltest_1.t1 values (1),(2),(3);GRANT ALL ON mysqltest_1.t1 TO mysqltest_1@'127.0.0.0/255.0.0.0';connect (n1,127.0.0.1,mysqltest_1,,mysqltest_1,$MASTER_MYPORT,$MASTER_MYSOCK);connection n1;show grants for current_user();select * from t1;disconnect n1;connection default;REVOKE ALL ON mysqltest_1.t1 FROM mysqltest_1@'127.0.0.0/255.0.0.0';delete from mysql.user where user like 'mysqltest\_1';flush privileges;drop table mysqltest_1.t1;## Bug #12302: 'SET PASSWORD = ...' didn't work if connecting hostname !=# hostname the current user is authenticated as. Note that a test for this# was also added to the test above.#grant all on mysqltest_1.* to mysqltest_1@'127.0.0.1';connect (b12302,127.0.0.1,mysqltest_1,,mysqltest_1,$MASTER_MYPORT,);connection b12302;select current_user();set password = password('changed');disconnect b12302;connection default;select host, length(password) from mysql.user where user like 'mysqltest\_1';revoke all on mysqltest_1.* from mysqltest_1@'127.0.0.1';delete from mysql.user where user like 'mysqltest\_1';flush privileges;grant all on mysqltest_1.* to mysqltest_1@'127.0.0.0/255.0.0.0';connect (b12302_2,127.0.0.1,mysqltest_1,,mysqltest_1,$MASTER_MYPORT,);connection b12302_2;select current_user();set password = password('changed');disconnect b12302_2;connection default;select host, length(password) from mysql.user where user like 'mysqltest\_1';revoke all on mysqltest_1.* from mysqltest_1@'127.0.0.0/255.0.0.0';delete from mysql.user where user like 'mysqltest\_1';flush privileges;drop database mysqltest_1;--source include/add_anonymous_users.inc# But anonymous users can't change their passwordconnect (n5,localhost,test,,test,$MASTER_MYPORT,$MASTER_MYSOCK);connection n5;--error 1044set password = password("changed");disconnect n5;connection default;--source include/delete_anonymous_users.inc# Bug #12423 "Deadlock when doing FLUSH PRIVILEGES and GRANT in # multi-threaded environment". We should be able to execute FLUSH# PRIVILEGES and SET PASSWORD simultaneously with other account# management commands (such as GRANT and REVOKE) without causing# deadlocks. To achieve this we should ensure that all account# management commands take table and internal locks in the same order.connect (con2root,localhost,root,,);connect (con3root,localhost,root,,);# Check that we can execute FLUSH PRIVILEGES and GRANT simultaneously# This will check that locks are taken in proper order during both# user/db-level and table/column-level privileges reloading.connection default;lock table mysql.user write;connection con2root;send flush privileges;connection con3root;send grant all on *.* to 'mysqltest_1'@'localhost';connection default;unlock tables;connection con2root;reap;connection con3root;reap;# Check for simultaneous SET PASSWORD and REVOKE.connection default;lock table mysql.user write;connection con2root;send set password for 'mysqltest_1'@'localhost' = password('');connection con3root;send revoke all on *.* from 'mysqltest_1'@'localhost';connection default;unlock tables;connection con2root;reap;connection con3root;reap;connection default;# Clean-updrop user 'mysqltest_1'@'localhost';disconnect con2root;disconnect con3root;# End of 4.1 tests## Bug#17279 user with no global privs and with create# priv in db can create databases#create database TESTDB;create table t2(a int);create temporary table t1 as select * from mysql.user;delete from mysql.user where host='localhost';INSERT INTO mysql.user VALUES('%','mysqltest_1',password('password'),'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0);INSERT INTO mysql.db VALUES('%','TESTDB','mysqltest_1','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','N','Y','Y','Y','Y','N');FLUSH PRIVILEGES;connect (con1,localhost,mysqltest_1,password,TESTDB);# The user mysqltest_1 should only be allowed access to# database TESTDB, not TEStdb# On system with "lowercase names" we get error "1007: Can't create db..."--error 1044, 1007create database TEStdb;# Clean-upconnection default;delete from mysql.user;delete from mysql.db where host='%' and user='mysqltest_1' and db='TESTDB';insert into mysql.user select * from t1;drop table t1, t2;drop database TESTDB;flush privileges;## BUG#13310 incorrect user parsing by SP#grant all privileges on test.* to `a@`@localhost;grant execute on * to `a@`@localhost;connect (bug13310,localhost,'a@',,test);connection bug13310;create table t2 (s1 int);insert into t2 values (1);--disable_warningsdrop function if exists f2;--enable_warningsdelimiter //;create function f2 () returns int begin declare v int; select s1 from t2into v; return v; end//delimiter ;//select f2();drop function f2;drop table t2;disconnect bug13310;connection default;REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost;drop user `a@`@localhost;## Bug#25578 "CREATE TABLE LIKE does not require any privileges on source table"#--disable_warningsdrop database if exists mysqltest_1;drop database if exists mysqltest_2;--enable_warnings--error 0,ER_CANNOT_USERdrop user mysqltest_u1@localhost;create database mysqltest_1;create database mysqltest_2;grant all on mysqltest_1.* to mysqltest_u1@localhost;use mysqltest_2;create table t1 (i int);# Connect as user with all rights on mysqltest_1 but with no rights on mysqltest_2.connect (user1,localhost,mysqltest_u1,,mysqltest_1);connection user1;# As expected error is emitted--error ER_TABLEACCESS_DENIED_ERROR show create table mysqltest_2.t1;# This should emit error as well--error ER_TABLEACCESS_DENIED_ERRORcreate table t1 like mysqltest_2.t1;# Now let us check that SELECT privilege on the source is enoughconnection default;grant select on mysqltest_2.t1 to mysqltest_u1@localhost;connection user1;show create table mysqltest_2.t1;create table t1 like mysqltest_2.t1;# Clean-upconnection default;use test;drop database mysqltest_1;drop database mysqltest_2;drop user mysqltest_u1@localhost;## Bug#18660 Can't grant any privileges on single table in database# with underscore char#grant all on `mysqltest\_%`.* to mysqltest_1@localhost with grant option;grant usage on *.* to mysqltest_2@localhost;connect (con18600_1,localhost,mysqltest_1,,);create database mysqltest_1;use mysqltest_1;create table t1 (f1 int);grant create on `mysqltest\_1`.* to mysqltest_2@localhost;grant select on mysqltest_1.t1 to mysqltest_2@localhost;connect (con3,localhost,mysqltest_2,,);connection con3;--error 1044create database mysqltest_3;use mysqltest_1;create table t2(f1 int);select * from t1;connection default;drop database mysqltest_1;revoke all privileges, grant option from mysqltest_1@localhost;revoke all privileges, grant option from mysqltest_2@localhost;drop user mysqltest_1@localhost;drop user mysqltest_2@localhost;--echo End of 5.0 tests
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?