天天看點

MySQL、PG、Oracle簡單指令差別

在自己虛拟環境中,模拟三個資料庫的不同指令,指令為查詢資料實驗所用。

M:MySQL P:postgresql O:Oracle

1.檢視所有資料庫:

M:show databases;

P:\l

O:ps -ef |grep pmon(檢視目前伺服器有哪些執行個體)

2.切換目前資料庫:

M:use database_name;

P:\c database_name

O:export ORACLE_SID=sid_name(切換執行個體名)

3.檢視目前有哪些表

M:show tables;

P:\dt

O:select table_name,owner from dba_tables where owner='USERNAME';

4.檢視表結構:

M:desc table_name;

P:\d table_name

O:desc table_name

5.建立普通使用者:

M:create user await@'%' identified by '1234';

MySQL建立使用者需要指定可通路的IP,%表示所有均可通路。遠端連接配接需要MySQL伺服器對遠端連接配接的使用者開啟對應權限。validate_password.length是密碼長度,validate_password.policy是密碼政策,

P:create role role_name login;(需要賦予登入權限login)

create user username with password 'password' valid until '2022-04-30';(建立帶有過期時間的使用者)

O:create user username identified by "password" temporary tablespace temp default tablespace users profile default;

6.檢視目前使用者權限。

M:show grants;(目前使用者),show grants for username@'%' ;(檢視使用者權限)

P:select * from information_schema.table_privileges where grantee='await_test';

O:select * from dba_sys_privs where grantee='grantee_name';

select * from dba_role_privs where grantee='grantee_name';(檢視擁有的角色)

select * from dba_tab_privs where grantee='grantee_name';(檢視單獨授予的權限)

7.建立角色并授予角色權限

M:create role await_test;grant select on sys.* to await_test;可将角色對應權限授予相應的使用者,這樣使用者就有了對應的權限。

P:create role await_test;GRANT select ON all tables in schema public to await_test;(授予隻讀權限)

O:create role role_name;grant dba to role_name;(将dba權限授予role)

8.檢視使用者密碼過期時間:

M:select,user,host,password_expired,password_last_changed,password_lifetime from mysql.user;

(password_expired的值是Y表示密碼過期,password_last_changed表示密碼修改時間,password_lifetime表示密碼有效期)

P:select * from pg_user;(valuntil時間即為過期時間)

O:select name,exptime,ptime from user$ where name='username';(ptime是密碼修改時間,exptime是過期時間)

9.設定使用者密碼永不過期(修改使用者密碼過期時間):

M:alter user username@'%' password expire never;

P:alter user username valid until '2022-05-30';alter user tes valid until 'infinity';(infinity表示永不過期)

O:修改使用者所在的profile中的參數PASSWORD_LIFE_TIME,unlimited表示無過期。

10.普通使用者登入:

M:mysql -u(username) -p(password) -h(伺服器IP) -P port

P:psql -U uname(使用者名) -W dbname(資料庫名)

O: sqlplus user/passwd@orcl

sqlplus user/[email protected]:1521/orcl

11.檢視目前資料庫下有哪些使用者:

M:select user,host,password_expired from mysql.user;

P:\du

O:select username,account_status from dba_users;

12.修改使用者密碼&繼續使用原密碼:

M:alter user username@'%' identified by 'password';

若無開啟密碼重用政策,則可繼續使用原密碼,已開啟密碼重用政策則需調整mysql.password_history(密碼重用次數)mysql.password_reuse_interval(密碼重用時間限制)

P:alter user username with password 'password';(pg_hba.conf裡的local設定為trust,則修改密碼後無法本地驗證,密碼到期後延長到期時間即可重用密碼)

O:alter user username identified by "password";(重置密碼)

密碼重用:select name,spare4 from user$;alter user username identified by values 'password/spare4';即可重用密碼。