1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP and MySQL Web Development - P58 ppsx

5 276 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 78,5 KB

Nội dung

257 Restoring Your MySQL Database Loading Data from a File One useful feature of MySQL that we have not yet discussed is the LOAD DATA INFILE statement.This can be used to load table data in from a file. It executes very quickly. This is a flexible command with many options, but typical usage is something like the following: LOAD DATA INFILE "newbooks.txt" INTO TABLE books; This will read row data from the file newbooks.txt into the table books. By default, data fields in the file must be separated by tabs and enclosed in single quotes, and each row must be separated by a newline (\n). Special characters must be escaped out with a slash (\). All these characteristics are configurable with the various options of the LOAD state- ment—see the MySQL manual for more details. To use the LOAD DATA INFILE statement, a user must have the FILE privilege dis- cussed earlier. Backing Up Your MySQL Database In MySQL, there are two ways to do a backup. The first way is to lock the tables while you copy the physical files, using a LOCK TABLES command.This has the syntax: LOCK TABLES table lock_type [, table lock_type ] Each table should be the name of a table, and the lock type either READ or WRITE.For a backup, you should only need a READ lock. Users and scripts will still be able to run read-only queries while you make your backup. If you have a reasonable volume of queries that alter the database, such as customer orders, this is not a practical solution. The second, and superior, method is using the mysql_dump command.Typical usage is something such as mysqldump opt all-databases > all.sql This will dump a set of all the SQL required to reconstruct the database to the file called all.sql. You should then stop the mysqld process for a moment and restart it with the log-update[=logfile] option.The updates stored in the log file will give you the changes made since your dump. (Obviously you should back up the log files in any nor- mal file backup.) Restoring Your MySQL Database If you need to restore your MySQL database, there are, again, a couple of approaches. If the problem is a corrupted table, you can run myisamchk with the -r (repair) option. 14 525x ch11 1/24/03 3:37 PM Page 257 258 Chapter 11 Advanced MySQL If you’ve used the first method for backup, then you can copy the data files back into the same locations in a new MySQL installation. If you have used the second method for backup, there are a couple of steps. First, you need to run the queries in your dump file.This will reconstruct the database up to the point where you dumped that file. Second, you will need to update the database to the point stored in the log files. Under UNIX, you can run a command such as ls -1 -t -r hostname.[0-9]* | xargs cat | mysql to process the log files in the correct order. More information about the process of MySQL backup and recovery can be found at the MySQL Web site: http://www.mysql.org Further Reading In these chapters on MySQL, we have focused on the uses and parts of the system most relevant to Web development, and to linking MySQL with PHP. If you want to know more, particularly with regard to non-Web applications, or MySQL administration, you can visit the MySQL Web site at http://www.mysql.com You might also want to consult Paul Dubois’ book MySQL,available from New Riders Publishing. Next We have now covered the fundamentals of PHP and MySQL. In Chapter 12,“Running an E-commerce Site,” we will look at the e-commerce and security aspects of setting up database-backed Web sites. 14 525x ch11 1/24/03 3:37 PM Page 258 III E-commerce and Security 12 Running an E-commerce Site 13 E-commerce Security Issues 14 Implementing Authentication with PHP and MySQL 15 Implementing Security Transactions with PHP and MySQL 15 525x part3 1/24/03 2:57 PM Page 259 15 525x part3 1/24/03 2:57 PM Page 260 12 Running an E-commerce Site THIS CHAPTER INTRODUCES SOME OF THE ISSUES involved in specifying, designing, building, and maintaining an e-commerce site effectively.We will examine your plan, possible risks, and some ways to make a Web site pay its own way. We will cover n What you want to achieve with your e-commerce site n Types of commercial Web site n Risks and threats n Deciding on a strategy What Do You Want to Achieve? Before spending too much time worrying about the implementation details of your Web site, you should have firm goals in mind, and a reasonably detailed plan leading to meet- ing those goals. In this book, we make the assumption that you are building a commercial Web site. Presumably then, making money is one of your goals. There are many ways to take a commercial approach to the Internet. Perhaps you want to advertise your offline services or sell a real-world product online. Maybe you have a product that can be sold and provided online. Perhaps your site is not directly intended to generate revenue, but instead supports offline activities or acts as a cheaper alternative to present activities. Types of Commercial Web Sites Commercial Web sites generally perform one or more of the following activities: n Publish company information through online brochures n Take orders for goods or services 16 525x ch12 1/24/03 2:57 PM Page 261 . at the MySQL Web site: http://www .mysql. org Further Reading In these chapters on MySQL, we have focused on the uses and parts of the system most relevant to Web development, and to linking MySQL. up database-backed Web sites. 14 525x ch11 1/24/03 3:37 PM Page 258 III E-commerce and Security 12 Running an E-commerce Site 13 E-commerce Security Issues 14 Implementing Authentication with PHP and MySQL 15. you can run a command such as ls -1 -t -r hostname.[ 0-9 ]* | xargs cat | mysql to process the log files in the correct order. More information about the process of MySQL backup and recovery can

Ngày đăng: 07/07/2014, 03:20

TỪ KHÓA LIÊN QUAN