# Mysql your visual blueprint for creating open source databases- P12

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:20

0
44
lượt xem
4

## Mysql your visual blueprint for creating open source databases- P12

Mô tả tài liệu

Mysql your visual blueprint for creating open source databases- P12:The show tables command displays a list of tables available in the currently selected database. You can use this command when you are unsure of the exact name of a table within the database.

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Mysql your visual blueprint for creating open source databases- P12

3. CONFIGURE MYSQL SECURITY 11 Most of the examples here use the ALL keyword as the privilege type. This keyword assigns all available privileges. You can also assign the specific privileges listed in the table below. PRIVILEGE ALLOWS ALTER Use ALTER TABLE command CREATE Use CREATE TABLE command DELETE Use DELETE command DROP Use DROP TABLE command FILE Use SELECT INTO OUTFILE and LOAD DATA INFILE INDEX Use CREATE INDEX or DROP INDEX INSERT Use INSERT command LOCK TABLES Use LOCK TABLES command PROCESS Use SHOW PROCESSLIST and mysqladmin processlist RELOAD Use the FLUSH command SELECT Use SELECT queries SHOW DATABASES Show all databases SHUTDOWN Shut down the server with mysqladmin shutdown SUPER Various administrative privileges including mysqladmin kill UPDATE Use UPDATE queries › Type GRANT ALL ON s This creates another user. Á Type REVOKE DELETE, s This removes the DELETE quotes and press Enter. This one has access to the DROP ON quotes and press and DROP privileges, leaving quotes table only. Enter. the user with the remaining ˇ Type TO fred IDENTIFIED privileges. BY 'other'; and press Enter. ‡ Type FROM fred; and press Enter. 209
6. MySQL VIEW A USER'S PRIVILEGES user's privileges. In this case, when you use SHOW GRANTS, Y ou can use the VIEW GRANTS command from the MySQL monitor to find out what privileges have been the results show a GRANT USAGE statement. USAGE is a granted to a particular user. This is useful if you need special privilege meaning "no privileges." In other words, to check what abilities have been given to a user. For the user can connect to the MySQL server but cannot example, the following statement displays the privileges access any databases or tables. granted to the user fred: When using SHOW GRANTS, remember that MySQL stores SHOW GRANTS FOR fred; users as a combination of username and hostname. If a username is configured with a specific host, you must The results for SHOW GRANTS are presented in the form specify the hostname to view their privileges. If you have of one or more GRANT statements. You can copy these created the user ted@localhost, for example, no privileges statements and use them to restore the user's privileges will be shown if you use this command: in the event of data loss, or use them to create another user with the same privileges. The password in the GRANT SHOW GRANTS FOR ted; statement is shown in encrypted form. Because no hostname is specified, this command looks for In some cases a user is configured in MySQL but does not a user with access from all hosts, and no user is found. To have any privileges. This can happen if you create a user show the privileges for the correct user, specify the manually in the users table, or if you have revoked all of a hostname with the @ symbol. VIEW A USER'S PRIVILEGES Note: The users referred to in this s The privileges for the user ¤ Type SHOW GRANTS FOR s This user's privileges are example were created in the section are displayed. fred; and press Enter. displayed. “Grant Privileges to Users.” Note: You must be connected to ⁄ From the MySQL monitor, MySQL as the root user or another type SHOW GRANTS FOR user that can grant privileges to use nancy; and press Enter. this command. 212
7. CONFIGURE MYSQL SECURITY 11 In order to use SHOW GRANTS, your username must have the GRANT OPTION in its list of privileges. When you display the privileges for a user, the encrypted password is shown in the GRANT statements, and this could be used to gain access to the user's resources. When you change a user's privileges using GRANT or REVOKE, the changes take effect immediately and are shown in subsequent SHOW GRANTS commands. The privileges are checked both when a user attempts to connect to the MySQL server and when they issue each command after connecting. You cannot use wildcards with SHOW GRANTS to display the privileges of multiple users. To display a list of users or quickly view privileges for multiple users, you can access the grant tables directly, as described in the next section. The GRANT statements shown when you use SHOW GRANTS are a summary of the user's privileges. While they can be used to recreate the user's privileges, they are not necessarily the same commands you used to assign the privileges and create the user. ‹ Type REVOKE ALL ON s This revokes all of the › Type SHOW GRANTS FOR s The user's privileges now testdb.quotes FROM fred; user's privileges. fred; and press Enter. include only the USAGE and press Enter. privilege, which allows access but no privileges. 213
12. MySQL INTRODUCING PHP This is only a brief introduction to PHP. PHP is a project of P HP is one of the most popular Web scripting languages, and one of the most popular languages for creating the Apache Software Foundation, and you can find out applications to work with MySQL. PHP is a scripting more or download software from the PHP Web site: language that is interpreted by Web servers. In particular, the www.php.net. popular open source Apache server can support PHP as a module, which allows for efficient execution of scripts. PHP and HTML Using Variables To use PHP, you embed a script within an HTML PHP supports variables, containers that can store document and save the document with the .php or numbers, text strings, or other data. PHP variables do not .php3 extension. The Web server looks for PHP scripts need to be defined before you use them, and they can in files with these extensions and interprets them store any type of data. The following example assigns a before sending the document to the Web browser. string value and a numeric value to two variables: Thus, the browser does not have access to the PHP script — only to the output of the script and the ?> tags. Anything between these two tags is interpreted as PHP rather than HTML. Anything outside these tags PHP also supports arrays, or variables with indexes. An should be valid HTML. array is basically a number of variables with a common name. The indexes for an array can be either numbers Create Output or string values. The following example assigns a value to an array element: PHP supports a number of commands. One basic example is the echo command, which sends output to semicolon. The following example displays a message using PHP: PHP variables can be included in string values. This is useful when you need to combine a variable's value PHP and MySQL PHP includes support for MySQL with a number of functions, described throughout this chapter. These allow you to connect to a MySQL server, submit a query to the server and retrieve the results, and perform other MySQL tasks. Virtually anything you can do with the MySQL monitor can also be done from a PHP script. 218
13. USING MYSQL WITH PHP 12 Using Functions Operators You can combine several statements into a group with a PHP supports a number of standard operators for function in PHP. To define a function, you use the working with numbers and strings. You can use these in function keyword and surround the statements with any expression to work with constants or variables. The braces. The following example defines a function called operators available in PHP are similar to those of print_bold: MySQL. The following table summarizes some of the basic PHP operators: - Subtraction The values in parentheses are the arguments, or * Multiplication parameters, of the function. To call a function, you / Division specify its name and the arguments in parentheses. The following statement calls the print_bold function: % Modulo (remainder) . Concatenation (combines strings) print_bold("This is a test."); Functions can also return a value using the return Conditional Statements keyword. When you call such a function, you can store You can use the if statement in PHP to perform one or its result in a variable. more statements conditionally. This statement uses a conditional expression followed by a single PHP Loops statement, or a block of statements enclosed in braces. PHP supports loops to perform a statement or a block For example, this if statement displays a message if the of statements multiple times. The while statement $num variable has a value greater than 30: defines a simple type of loop that repeats as long as a condition is true. The following is an example of a if ($num > 30) echo "It's bigger than while loop: 30."; while ($num < 30) { The condition in an if statement can use one or more$num = $num + 1; conditional operators. These are similar to the echo "The number is$num."; conditional operators in MySQL, and are summarized in } the table below. PHP also supports for loops. This type of loop starts OPERATOR MEANING with a for statement specifying a beginning value, a condition, and an increment expression for a variable. == Is equal to The following for loop is equivalent to the previous != Is not equal to while example: > Is greater than for ($num=0;$num= Is greater than or equal to }
15. USING MYSQL WITH PHP 12 For Windows servers, a binary version of PHP is available from the PHP Web site at www.php.net. PHP for Windows is available in two packages: one as a .zip archive, and a second as an .exe file that automatically begins the installation. Both packages include built-in support for MySQL, so you do not need to change the configuration to support MySQL. If you are using Microsoft's IIS (Internet Information Server) or PWS (Personal Web Server), included with some versions of Windows, the .exe version of the PHP binary will automatically configure your server to work with PHP. If you are using the Apache Web server under Windows, download the .zip version of the PHP package. This includes everything you need to support PHP as an Apache module. At this writing, this feature only works reliably with PHP 1.x, and does not yet support the new PHP 2.x versions. The www.php.net site includes links to external sites where you can find binary versions of PHP for Mac OS X, Novell NetWare, and a variety of other systems. › Type ?> to end the PHP Note: Use the appropriate command Á Type the URL for the test s If the PHP information is script. for the editor you are using. file into a Web browser. displayed, PHP is working on your server. ˇ Press Ctrl-X and then Y to save the file and exit the editor. 221
19. USING MYSQL WITH PHP 12 The phpMyAdmin utility includes several other options for working with tables. The Export page allows you to export data from the table. You can choose to export the table data, the table structure, or both. An option is included to format the data in a CSV format that can be imported into Microsoft Excel, or you can customize the formatting. You can also choose to limit the number of rows of data that will be included in the exported file. The Operations page includes an interface to several MySQL options, including options to sort the table data by a particular column value, rename the table, move it to a different database or table, or copy it to another table. There are also options to optimize or repair the table. The Options page allows you to modify the table options. This includes the table type, the comment associated with the table, and a number of other options. Two final options are included for tables: Empty deletes all of the rows of a table, and Drop deletes the table completely. Both of these prompt you for confirmation before deleting anything. s The first ten rows of the ‹ Click the Edit button next s The columns of the s From this screen, you can table are displayed. to a row to edit the row. selected row are displayed modify the row and save it, or in a form. create a new table row based on the same data. 225