You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
mysql -u [user] -p
ENTER PASSWORD: [password]
-----
mysql -u root -p
Create user
CREATE USER 'admin'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Set Password
SET PASSWORD FOR '[username]'@'%' = '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'; ## password='password'
GRANT ALL PRIVILEGES ON *.* TO '[username]'@'%' WITH GRANT OPTION;
---
SET PASSWORD FOR 'admin'@'%' = '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'; ## password='password'
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
Create/drop database
CREATE DATABASE [db_name];
DROP DATABASE [db_name];
Create/drop table
CREATE TABLE [db_name.tbl_name];
DROP TABLE [db_name.tbl] IF EXIST;
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
-----
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
Change access for all host
USE mysql;
UPDATE user set host='[hostname]' where user='[username]' and host='localhost';
FLUSH PRIVILEGES;
-----
UPDATE user set host='%' where user='root' and host='localhost';
FLUSH PRIVILEGES;
psql
\du
-----
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
zeroc0d3 | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Change owner database
psql
\l # list databases
ALTER DATABASE [db_name] OWNER TO '[username]';
Change password user
psql
\du # list users & roles
ALTER USER [username] PASSWORD '[password]';
Change user roles
psql
\du # list users & roles
ALTER ROLE [username] [role_name]; ## Superuser, Create role, Create DB, Replication, Bypass RLS
-----
ALTER ROLE deploy SUPERUSER;
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------------------+-----------
deploy | Superuser | {}
zeroc0d3 | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Rename user
psql
\du # list users & roles
ALTER USER [username] RENAME TO '[username_new]';
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------------------+-----------
deploy_new | Superuser | {}
zeroc0d3 | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Rename database
psql
\l # list databases
ALTER DATABASE [db_name] RENAME TO '[db_name_new]';
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------------------+-----------
deploy_new | Superuser | {}
zeroc0d3 | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}