`

Learning PHP-MySQL基础知识

阅读更多
引用
关系数据库中有三种基本的关系类型。根据关系双方所含对象的多少,可以将这些关系氛围一对一、一对多、多对多三种关系。

最少权限原则:
一个用户(或者一个进程)应该拥有能够执行分配给他的任务的最低级别的权限。
创建用户:GRANT命令
GRANT和REVOKE命令分别用来授予和取消MySQL用户的权限,这些权限分四个级别。他们分别是:
  • 全局
  • 数据库

mysql> help grant;
Name: 'GRANT'
Description:
Syntax:
GRANT
    priv_type [(column_list)]
      [, priv_type [(column_list)]] ...
    ON [object_type] priv_level
    TO user_specification [, user_specification] ...
    [REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}]
    [WITH with_option ...]

GRANT PROXY ON user_specification
    TO user_specification [, user_specification] ...
    [WITH GRANT OPTION]

object_type:
    TABLE
  | FUNCTION
  | PROCEDURE

priv_level:
    *
  | *.*
  | db_name.*
  | db_name.tbl_name
  | tbl_name
  | db_name.routine_name

user_specification:
    user
    [
        IDENTIFIED BY [PASSWORD] 'password'
      | IDENTIFIED WITH auth_plugin [AS 'auth_string']
    ]

ssl_option:
    SSL
  | X509
  | CIPHER 'cipher'
  | ISSUER 'issuer'
  | SUBJECT 'subject'

with_option:
    GRANT OPTION
  | MAX_QUERIES_PER_HOUR count
  | MAX_UPDATES_PER_HOUR count
  | MAX_CONNECTIONS_PER_HOUR count
  | MAX_USER_CONNECTIONS count

The GRANT statement grants privileges to MySQL user accounts. GRANT
also serves to specify other account characteristics such as use of
secure connections and limits on access to server resources. To use
GRANT, you must have the GRANT OPTION privilege, and you must have the
privileges that you are granting.

Normally, a database administrator first uses CREATE USER to create an
account, then GRANT to define its privileges and characteristics. For
example:

CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL ON db1.* TO 'jeffrey'@'localhost';
GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;

However, if an account named in a GRANT statement does not already
exist, GRANT may create it under the conditions described later in the
discussion of the NO_AUTO_CREATE_USER SQL mode.

The REVOKE statement is related to GRANT and enables administrators to
remove account privileges. See [HELP REVOKE].

When successfully executed from the mysql program, GRANT responds with
Query OK, 0 rows affected. To determine what privileges result from the
operation, use SHOW GRANTS. See [HELP SHOW GRANTS].

URL: http://dev.mysql.com/doc/refman/5.5/en/grant.html


REVOKE命令
与GRANT相反的命令。用来从一个用户收回权限。
mysql> help revoke;
Name: 'REVOKE'
Description:
Syntax:
REVOKE
    priv_type [(column_list)]
      [, priv_type [(column_list)]] ...
    ON [object_type] priv_level
    FROM user [, user] ...

REVOKE ALL PRIVILEGES, GRANT OPTION
    FROM user [, user] ...

REVOKE PROXY ON user
    FROM user [, user] ...

The REVOKE statement enables system administrators to revoke privileges
from MySQL accounts. Each account name uses the format described in
http://dev.mysql.com/doc/refman/5.5/en/account-names.html. For example:

REVOKE INSERT ON *.* FROM 'jeffrey'@'localhost';

If you specify only the user name part of the account name, a host name
part of '%' is used.

For details on the levels at which privileges exist, the permissible
priv_type and priv_level values, and the syntax for specifying users
and passwords, see [HELP GRANT]

To use the first REVOKE syntax, you must have the GRANT OPTION
privilege, and you must have the privileges that you are revoking.

To revoke all privileges, use the second syntax, which drops all
global, database, table, column, and routine privileges for the named
user or users:

REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...

To use this REVOKE syntax, you must have the global CREATE USER
privilege or the UPDATE privilege for the mysql database.

URL: http://dev.mysql.com/doc/refman/5.5/en/revoke.html


例子:
mysql > grant all on * to eric identified by '123456' with grant option;
mysql > revode all privileges, grant from eric;

创建一个没有任何权限的常规用户:
mysql > grant usage on books.* to sally identified by '123456';

授予权限
mysql > grant select,insert,update,delete,index,alter,create,drop on books.* to sally;

收回权限
mysql > revoke alter,create,drop on books.* from sally;
mysql > revoke all on books.* from sally;

创建一个Web用户
授予增删改查的权限
mysql > grant select,insert,delete,update on books.* to user_a identified by '123456';

创建索引:
mysql> help create index;
Name: 'CREATE INDEX'
Description:
Syntax:
CREATE [ONLINE|OFFLINE] [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
    [index_type]
    ON tbl_name (index_col_name,...)
    [index_option] ...

index_col_name:
    col_name [(length)] [ASC | DESC]

index_type:
    USING {BTREE | HASH}

index_option:
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name
  | COMMENT 'string'

CREATE INDEX is mapped to an ALTER TABLE statement to create indexes.
See [HELP ALTER TABLE]. CREATE INDEX cannot be used to create a PRIMARY
KEY; use ALTER TABLE instead. For more information about indexes, see
http://dev.mysql.com/doc/refman/5.5/en/mysql-indexes.html.

URL: http://dev.mysql.com/doc/refman/5.5/en/create-index.html

SQL是什么
SQL全称是Structured Query Language
表关联的总结
MySQL中的关联类型
名称                   描述
  • 笛卡尔儿乘积       所有表所有行的所有关联。实现方法,在列的名称之间指定一个逗号,而            
  •                              不是指定一个WHERE字句。  
  • 完全关联             同上
  • 交叉关联             同上,也可以通过在关联的表明之间指定CROSS JOIN关键词的指定。
  • 内部关联             如果没有WHERE条件,等价于完全关联。
  • 等价关联             在关联中使用一个带“=”号的条件表达式匹配来自不同表中的行。
  • 左关联               试图匹配表的行并在不匹配的行中填入NULL,在SQL中使用LEFT JOIN关键词。



参考资料:
PHP&MySQL.Web


分享到:
评论

相关推荐

    dokumen.pub_learning-php-mysql-amp-javascript-a-step-by-step-guide-to-creating-dynamic-websites-6nbsped-1492093823-9781492093824-a-3947587.pdf

    《Learning PHP, MySQL & JavaScript》第六版是学习PHP、MySQL和JavaScript的非常实用的指南,涵盖了动态网站开发的每个方面,从基础知识到实际应用。该书适合初学者和经验丰富的开发者,旨在帮助读者快速掌握动态...

    learning php-2.rar_Learning Php_php

    在“Learning PHP”的第二部分,我们可能将探讨以下关键知识点: 1. **PHP基础语法**:包括变量的声明、数据类型(如字符串、整型、浮点型、布尔型、数组和对象)、常量、运算符、流程控制(如条件语句if/else、...

    Learning PHP, MySQL, JavaScript, CSS & HTML5, 3rd Edition

    《Learning PHP, MySQL, JavaScript, CSS & HTML5, 3rd Edition》这本书全面介绍了构建现代动态网站所需的技术栈。通过学习这些技术,不仅可以掌握创建交互性强、功能丰富的网站的方法,还能深入了解每个工具的工作...

    Learning PHP MySQL Javascript CSS and HTML5

    通过对PHP、MySQL、JavaScript、CSS和HTML5的全面讲解,本书旨在帮助读者建立起现代Web开发的基础知识体系。读者通过本书的学习,将能够理解和运用这些技术进行Web内容的开发,并逐步构建起功能丰富的动态网站。无论...

    learning php-3.rar_Learning Php_php

    《学习PHP-3》是关于Web开发的PHP学习资料的第三部分,主要涵盖了在Web开发领域使用PHP语言的深入知识和实践技巧。本压缩包包含一个名为“4_420741000680439845.pdf”的文件,可以预期它是该系列教程的文档或教材,...

    Learning PHP and MySQL 2nd Edition

    总之,《学习PHP与MySQL第二版》是一本全面介绍了PHP和MySQL基础知识及高级应用的书籍,对于想要学习这两项技术的读者来说是非常有价值的参考资料。此外,书中提到的其他资源也为进一步学习提供了丰富的途径。

    [nixon_robin]_learning_php,_mysql_&_javascript__w.pdf

    本书《Learning PHP, MySQL & JavaScript with jQuery, CSS & HTML5》是由Robin Nixon撰写,目前是第五版。这本书是一本面向初学者的PHP、MySQL和JavaScript等Web技术的教材。Robin Nixon是一位资深的IT培训专家,他...

    Learning PHP & MySQL, 2nd Edition.pdf

    3. “Learning PHP & MySQL, 2nd Edition.pdf”指的是一本名为《学习PHP和MySQL》的第二版电子书,这本书专门针对PHP语言和MySQL数据库的学习者。 4. 第二版意味着相比于第一版,书中内容可能进行了更新或改进,可能...

    Learning PHP,MySQL and JavaScript (5th)

    《Learning PHP, MySQL and JavaScript (5th)》第五版涵盖了以下知识点: 1. 动态网页内容的介绍:解释了动态内容与静态内容的区别,以及为什么动态内容在现代Web开发中非常重要。 2. PHP编程基础:包括PHP的基本...

    [PHP.MySQL.JavaScript学习手册].(Learning.PHP.MySQL.and.JavaScript).Robin.Nixon

    - **HTTP 和 HTML:Berners-Lee 的基础知识** HTTP(超文本传输协议)是一种应用层协议,用于在客户端和服务器之间传输数据。HTML(超文本标记语言)是用于创建网页的标准标记语言。这两者共同构成了万维网的基础...

    learning-PHP.zip_Learning Php

    本文将根据"learning-PHP.zip_Learning Php"的资源,深入讲解PHP的基础知识。 1. **安装与环境配置** 在开始学习PHP之前,你需要在本地安装一个支持PHP的Web服务器环境,如XAMPP或WAMP。这些集成环境包含了Apache...

    Learning-PHP-MySQL-JavaScript.zip_WEB开发_PHP_

    《Learning PHP MySQL JavaScript With jQuery CSS HTML5》是第四版的一本综合性的Web开发教程,它涵盖了从基础到高级的多项关键技术,旨在帮助读者构建动态、交互式的网页应用。这本书的知识点丰富多样,主要包括...

    深入学习PHP,MySQL,javascript,CSS,html5

    书中不仅介绍了这些技术的基础知识,还探讨了如何将这些技术有效地结合起来,创建功能强大且优化的Web应用。通过阅读这本书,读者可以学会如何设计、开发和优化一个完整的Web应用,从而提升自己的技术栈和职业竞争力...

    Learning PHP MySQL & JavaScript(4th) pdf 0分

    在内容编排上,本书首先对PHP编程语言进行了深入浅出的介绍,包括面向对象编程的基础知识。这一部分对于理解PHP的高级特性至关重要,也为读者后续学习数据库编程奠定了基础。作者详细讲解了PHP的基础语法,同时通过...

    Learning PHP, MySQL and JavaScript with jQuery, CSS and HTML5

    这本书《Learning PHP, MySQL and JavaScript with jQuery, CSS and HTML5》是针对初学者介绍几种关键的Web开发语言的入门级教材。在Web开发领域,PHP、MySQL、JavaScript、jQuery、CSS和HTML5是非常重要的技术栈,...

Global site tag (gtag.js) - Google Analytics