简体   繁体   中英

Grant privileges to all users mysql?

Actually i am making java app...and it is creating a database and table in the database on the first run..now i want it to grant select,create,insert on that table to all the users present in mysql..and even if a new user is created it should have privileges on that table too...i have tried alot of stuff from the internet heres the queries i have tried executing

grant select,create,insert on db.table to PUBLIC
grant select,create,insert on db.table to ''@'%'
grant select,create,insert on db.able to '*'@'%'

please help me with it... this is my javacode for the creation of database and table on the first run

st=conn.createStatement();

            ResultSet r=conn.getMetaData().getCatalogs();boolean dbe=false;
            while(r.next())
            {
                if(r.getString(1).equalsIgnoreCase("DB"))
                    {
                        st.execute("use db");
                        dbe=true;
                    }
            }
            if(!dbe)
            {
                st.execute("create database db");
                st.execute("use db");
                st.execute("create table tab(name varchar(255),address varchar(80),at datetime)");
            }

For granting privileges to all database:

GRANT ALL PRIVILEGES ON .* TO 'myuser'@'%' WITH GRANT OPTION;

For granting privileges to a specific database:

GRANT ALL PRIVILEGES ON database_name.* TO 'myuser'@'%' WITH GRANT OPTION;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM