0% found this document useful (0 votes)
68 views

Chapter01 Lesson08 (Administration)

1. MySQL uses an access control system to manage user authentication and privileges. When a client connects to the server, the username and password are verified and the user's privileges are returned. 2. The main tables used for access control in MySQL are the user, db, table_priv, columns_priv, and procs_priv tables, which define user accounts, database privileges, and privileges for objects like triggers, views, stored functions and procedures. 3. Users and privileges can be created, modified, and revoked using SQL statements like CREATE USER, GRANT, REVOKE, and DROP USER. Privileges control access at the global, database, table, and column level and include privileges

Uploaded by

BUNKHY LEM
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Chapter01 Lesson08 (Administration)

1. MySQL uses an access control system to manage user authentication and privileges. When a client connects to the server, the username and password are verified and the user's privileges are returned. 2. The main tables used for access control in MySQL are the user, db, table_priv, columns_priv, and procs_priv tables, which define user accounts, database privileges, and privileges for objects like triggers, views, stored functions and procedures. 3. Users and privileges can be created, modified, and revoked using SQL statements like CREATE USER, GRANT, REVOKE, and DROP USER. Privileges control access at the global, database, table, and column level and include privileges

Uploaded by

BUNKHY LEM
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1

MySQL Administration
Manage user, Manage Privileges, Backup & Restore Database
MySQL Access Control System 2

• Process of Client connect to Server


• Connection Verification (check username and password)
• Request verification (return privileges of user access)

• Main 5 table in MySQL


• user: user account & global privileges

• db: object privileges (triggers, views, …)


• table_priv នង
ិ columns_priv
• procs_priv: stored function & stored procedures privileges
Create User 3

CREATE USER user


IDENTIFIED BY password

• User format
username@hostname
ex: dbadmin@localhost
View the privileges of a user account 4

• SHOW GRANTS FOR dbadmin@localhost;

• To allow a user account to connect from any host, you use the
percentage (%) wildcard
CREATE USER superadmin@'%'
IDENTIFIED BY 'secret';
To connect to the database server from any 5
subdomain

CREATE USER mysqladmin@'%.mysqltutorial.org'


IDENTIFIED by 'secret';
Omit the hostname 6

CREATE USER remote;

SHOW GRANTS FOR remote;


Naming User Name 7

It’s important to note that the quote is very important especially when
the user account contains special characters such as _ or % .

CREATE USER 'api@localhost’;

SHOW GRANTS FOR 'api@localhost';


ការកែប្រែលេខសម្ងា ត់ដោយ​ប្រើ UPDATE 8
Statement
USE mysql;
 
UPDATE user
SET password = PASSWORD('Secret1970')
WHERE user = 'mysqltutorial' AND
      host = 'mysqltutorial.org';
 
FLUSH PRIVILEGES;
Continue… 9

• ការកែប្រែលេខសម្ងា ត់ដោយ​ប្រើ SET PASSWORD Statement

SET PASSWORD

FOR 'mysqltutorail'@'mysqltutorial.org' = PASSWORD('Secret1970')

• ការកែប្រែលេខសម្ងា ត់ដោយ​ប្រើ GRANT USAGE Statement

GRANT USAGE ON *.* TO [email protected]

IDENTIFIED BY ‘Secret1970’
ការផ្តល់សទ
ិ ្ធទៅ
ិ ឱ្យ User 10

GRANT privileges (column_list) - Privileges: កំណត់សិទ្ធិណាមួយដែលផ្តល់​ឱ្យ User


- Column_list: ឈ្មោ ះរបស់​Column ដែលត្រូវផ្តល់​សិទ្ធិលើ
ON [object_type] privilege_level
- Privilege_level: កម្រត
ិ នៃការ​ផ្តល់​សទ
ិ ្ធជា
ិ global, database-
TO account specific, table-specific, ឬ column-specific privileges

[IDENTIFIED BY 'password'] - Account: ឈ្មោ ះរបស់ user account


- Password: កំណត់​លេខសម្ងា ត់។ ប្រសិន​បើ Account មាន​ស្រាប់ វា​
WITH GRANT OPTION និង​ដូរលេខសម្ងា ត់​ចាស់​ដោយ​យក​លេខ​សម្ងា ត់​ថ្មីនេះ
- WITH GRANT OPTION: សម្រាប់​ឱ្យ User account មួយនេះ​ផ្តល់​
សទ
ិ ្ធ​ប
ិ ន្តរ​នៅល​ើ Object មួយនេះ។
ឧទាហរណ៍ 11

• ប្រសន
ិ ​ប​អ
ើ ក
្ន ​ត្រូវ​ការ​បង្កើត user មួយ​ដែលមានសទ
ិ ្ធិ Full Control (super account)

CREATE USER 'super'@'localhost' IDENTIFIED BY 'SecurePass1';


GRANT ALL ON *.* TO 'super'@'localhost' WITH GRANT OPTION;

• កំណត់លើ Database ណាមួយ

CREATE USER 'super2'@'%' IDENTIFIED BY 'SecurePass2';


GRANT ALL ON classicmodels.* TO 'super2'@'%' WITH GRANT OPTION;
ផ្តល់សទ
ិ ្ធជា
ិ ក់លាក់មួយចំនួនទៅកាន់ Users 12

CREATE USER 'rfc'@'%' IDENTIFIED BY 'SecurePass3';


 
GRANT SELECT, UPDATE, DELETE ON classicmodels.* TO rfc;
សទ
ិ ្ធដែ
ិ លអ្នក​អាចប្រប្រា
ើ ស់​បាន​នៅក្នុង MySQL
GRANT មាន​ដូចខាងក្រោម
13

• ALL • EVENT • REPLICATION CLIENT


• ALTER • EXECUTE • REPLICATION SLAVE
• ALTER ROUTINE • FILE • SELECT
• CREATE • GRANT OPTION • SHOW DATABASES
• CREATE ROUTINE • INDEX • SHOW VIEW
• CREATE TABLESPACE • INSERT • SHUTDOWN
• CREATE TEMPORARY • LOCK TABLES • SUPER
TABLES • PROCESS • TRIGGER
• CREATE USER • PROXY • UPDATE
• CREATE VIEW • REFERENCES • USAGE
• DELETE • RELOAD
• DROP
ការដកសទ
ិ ្ធចេ
ិ ញពី User 14

• Syntax
REVOKE   privilege_type [(column_list)]      [, priv_type
[(column_list)]]...
ON [object_type] privilege_level
FROM user [, user]...

• សម្រាប់ការដកសទិ ្ធទា
ិ ងំ អស់​មកវញ​
ិ អ្នក​ត្រូវប្រប្រា
ើ ស់​ឃ្លា ​បញ្ជា ​ដូចខាងក្រោម
REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user]…
ឧទាហរណ៍ 15

SHOW GRANTS FOR 'rfc'@'localhost';


 
REVOKE SELECT, UPDATE, DELETE
ON 'classicmodels’.* FROM 'rfc'@'localhost’;
 
លុប Users 16

DROP USER [IF EXISTS] user, [user],...;

SHOW PROCESSLIST;

KILL 40;
Quiz (10 Marks) ? 17

1. ចូរបង្កត
ើ User SN នង
ិ ដាក់ Password អ្វក
ី ៏បាន ដោយប្រើ host=localhost។
2. ដូរ Password ផ្សេង

3. ចូរផ្តល់សទ
ិ ្ធិ SELECT, INSERT, UPDATE, DELETE លើ Objects ទាំងអស់របស់
Database classicmodels ទៅឱ្យ User SN។

4. ចូរដកសទ
ិ ្ធិ DELETE ពី User SN វញ។

5. លុប User SN ចេញវញ។



ការបង្កើ User តាមរយៈ MySQL Workbench 27
Tool
• Login: ប្រើសម្រាប់មើលព័ត៌មានរបស់​User
ណាមួយ

• Account Limits: ប្រស


ើ ម្រាប់​កំណត់ចំនួននៃ
ការប្រប្រា
ើ ស់ Query របស់ User ណាមួយក្នុង
មួយម៉ោ ង

• Administrative Roles: ប្រើសម្រាប់ផ្តស់សិទ្ធិជា


Admin ឱ្យ User

• Schema Privileges: ប្រស


ើ ម្រាប់​កំណត់សទ
ិ ្ធនៅ

លើ Database ណាមួយ
Administrative Roles: ប្រស
ើ ម្រាប់ផ្តស់សទ
ិ ្ធជា

Admin ឱ្យ User
28

• DBA: ផ្តល់សទ
ិ ្ធទា
ិ ងំ អស់
• MaintenanceAdmin: សិទ្ធិសម្រាប់ជូសជុល MySQL server
• ProcessAdmin: សទ
ិ ្ធស
ិ ម្រាប់គ្រប់គ្រង Process
• UserAdmin: សទ
ិ ្ធស
ិ ម្រាប់បង្កត
ើ User នង
ិ ប្តូរ Password
• SecurityAdmin: សិទ្ធិសម្រាប់ការ​គ្រប់គ្រង Login
• MonitorAdmin: សទ
ិ ្ធក
ិ ុ ងការត្រួ
្ន តពន
ិ ត
ិ ្យ MySQL server
• DBManager: សទ
ិ ្ធក
ិ ុ ងការ​
្ន គ្រប់គ្រង Database
• DBDesigner: សិទ្ធិកុ ង​
្ន ការ​បង្កើត Database Schema
• ReplicationAdmin: សទ
ិ ្ធក
ិ ុ ងការ​
្ន គ្រប់គ្រង Replication
• BackupAdmin: សទ
ិ ្ធក
ិ ុ ងការ​
្ន Backup Database
មើលសិទ្ធិរបស់​User ដ៏ទៃ។
• Custom: សិទ្ធិកុ ងការ​
្ន
ការថែទាំ MySQL Database Tables 29

• ការប្រប្រា
ើ ស់ Analyze table (Error Data on Key Distribution)
ANALYZE TABLE payments
• ការប្រប្រា
ើ ស់ Optimize table (Optimize Size of Database)
OPTIMIZE TABLE orders;
• ការប្រប្រា
ើ ស់ Check Table (Check Error when database crash)
CHECK TABLE orders
• ការ​ប្រប្រា
ើ ស់​Repair Table Statement
REPAIR TABLE employees
ការត្រួតពន
ិ ត
ិ ្យClient Connection 30

• Client Connection ប្រស


ើ ម្រាប់​
មល
ើ ព័ត៌មាន​របស់ Client ដែល
កំពុង Connect ចូល​មក​ប្រប្រា
ើ ស់
MySQL Server។ អ្នក​អាច​ផ្អា ក
Connection, បញ្ឈប់ Connection
ើ ព័ត៌មានដ៏ទៃទៀតរបស់
ឬ មល
Connection Client។
ការប្រប្រា
ើ ស់ Server Logs 31

Server Logs ត្រូវ​បាន​គេបែងចែកជាពរី


Tabs គឺ

• Slow Log File: មល


ើ Slow Log File
• Error Log File: មល
ើ ព័តមា
៌ ន​នៃការ
Error របស់ MySQL។
ការប្រប្រា
ើ ស់ Server Status 32

• នៅលើ Server Status យង


ើ ​អាចមល
ើ ព័តមា
៌ ន​
មួយ​ចំនួន​របស់ MySQL Server ដូចជា
• Server’s running state (stopped/running)
• Available Server Features: តើមាន​មុខងា​អ្វីខ្លះ
ដែលអាចប្រប្រា
ើ ស់​បាន
• Server Directories: មល
ើ ទតា
ី ងំ របស់ MySQL
Server
• …
ការ Export នង
ិ Import Data Table 33

ការ Export នង
ិ Import Data
Table នេះ​អាច​ប្រប្រា
ើ ស់ CSV
នង
ិ JSON File បាន ដែលបាន​
បន្ថែម​នូវ​ជំរស​
ើ ជា​ច្រន
ើ ​នៅក្នុង​
នោះ ដូចជា (Separators,
column selection, encoding
selection, …)។
34

អ្នក​អាច​ប្រប្រា
ើ ស់
Query រួចធ្វកា
ើ រ​
Export/Import ទន
ិ ្នន័យ​
បាន​តាមរយៈរូប
ខាងក្រោម
ការ Export នង
ិ Import Database ដោយប្រើ 35
MySQL Workbench
ការប្រប្រា
ើ ស់ Performance Dashboard 36

• Network Status

ប្រស
ើ ម្រាប់ម​ល
ើ ​ចរាចរណ៍នៃ Network រវាង​ការបញ្ជួ ន​នង
ិ ​ការ​ទទួល​ព័ត៌មាន​
ពី Client Connection។

• MySQL Status

មើលព័ត៌មាន​នៃការ​ប្រើប្រាស់ Cache​របស់ Table, ដំណើការនៃ SQL

Statements និងចំនួនការ​ប្រើប្រាស់ INSERT, UPDATE, DELETE, CREATE,

ALTER នង
ិ DROP Statements ក្នុងមួយ​វ ិនាទនៅ
ី ល​ើ MySQL Server។ 

• InnoDB Status

មល
ើ ព័ត៌មាន​នៃ​ការ​ប្រប្រា
ើ ស់​Buffer Pool នៅលើ Disk ដែលទាក់ទង​នង
ិ ​ការ
Read នង
ិ Write ចូល។
ការ Backup Database ដោយប្រប្រា
ើ ស់ 37
mysqldump Tool
“C:\Program Files\MySQL\MySQL Server 5.7\bin”
mysqldump -u [username] -p[password] -P [Port] [database_name] > [dump_file.sql]
• ការ Backup តែ Structure
mysqldump -u mysqltutorial -psecret -P 3307  --no-data=true classicmodels > backup002.sql
• ការ Backup តែ Data
mysqldump -u mysqltutorial -psecret​--no-create-info=true classicmodels > backup002.sql
• ការ Backup ច្រើន Database ក្នុងពេលតែមួយ
mysqldump -u [username] -p[password]  [dbname1,dbname2,…] > [dump_file.sql]
mysqldump -u [username] -p[password] --all-database=true > [dump_file.sql]
ការ Restore Database ដោយប្រប្រា
ើ ស់ 38
Command Line
“C:\Program Files\MySQL\MySQL Server 5.7\bin”
mysql -u [username] -p[password] -P [Port];
Create database if exists [databasename];
Use [databsename];
Source backup.sql;
Summery 39

• Create user
• View Privileges
• Change user password
• Grant privileges to user
• Revoke privileges from user
• User mysql workbench to control user
• Export and Import data with tool and command line

You might also like