Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 15 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
15
Dung lượng
729,12 KB
Nội dung
GETTING STARTED WITH MYSQL 38 3. Type: SELECT id, first, last FROM name ►► ORDER BY id; The window should look like this: In this query, ORDER BY id places the records in numeric order, based on their id numbers. Tip: To arrange records in reverse numeric or reverse alphabetical order, add DESC on the end. For instance, type: SELECT first, last FROM name ORDER BY last DESC; The DESC option refers to the word “descending.” It tells MySQL to order things descending from high to low instead of the default: low to high. GETTING STARTED WITH MYSQL 39 4. Type: \q; then press ENTER. This closes your MySQL database connection. You are now logged out of the MySQL server: the mysql> prompt is gone. GETTING STARTED WITH MYSQL 40 5. Type: exit then press ENTER. The Konsole window should close. GETTING STARTED WITH MYSQL 41 Giving MySQL commands to a Web server MySQL’s client/server arrangement makes it well-suited to Web applications. With MySQL server running on a Web server, you can use a MySQL client to update/add/delete data remotely. This book assumes that you’ve installed MySQL on your desktop Linux computer. Both the MySQL client and server programs are on this computer, called localhost. To give commands to a MySQL server program running on a Linux Web server, just replace localhost with the IP address of the Web server, such as 10.0.1.10 or the domain name of the Web server, such as mysql.domain.com Provided you have an Internet connection with the Web server, and the proper username/password to access it, your commands will work. GETTING STARTED WITH MYSQL 42 ADMINISTERING DATABASES 43 Administering Databases In this section, you’ll learn how to: • Restart MySQL • Back up a database • Delete a table • Delete a database • Restore a database ADMINISTERING DATABASES 44 Restart MySQL If you’ve shut off your computer since the last exercise, you might need to restart MySQL. First, login to your Linux computer as the Root user. Then restart the MySQL server: 1. Open the Konsole window and login as the Root user. 2. At the prompt, type: /etc/rc.d/init.d/mysql start then press ENTER. 3. Type: exit then press ENTER. You’re now logged out of the Linux Root account. ADMINISTERING DATABASES 45 Now you’ll have to establish a MySQL client connection to the MySQL server: 4. At the $ prompt, type: mysql –u root –p then press ENTER. 5. Type the password used to gain root access to the MySQL server: textbook then press ENTER. ADMINISTERING DATABASES 46 The window should look like this: ADMINISTERING DATABASES 4 7 Back up a database 1. Make sure the Konsole window is open. If it’s not, open it. 2. Make sure you’re logged out of the MySQL server. Tip: Give the \q; command. 3. At the[yourusername@localhost yourusername]$ prompt, type: pwd then press ENTER. The window should look something like this: [...]...The Linux command pwd is an acronym for print working directory In other words, “print the path to the directory I’m working in.” When you first open the Konsole window, Linux automatically goes to your home directory Each user on a Linux computer has his own home directory, which contains preferences and files unique to that user 48 ADMINISTERING DATABASES 4 Type: cd / then press ENTER The window... cd / then press ENTER The window should look something like this: This Linux command has two parts: cd tells the computer to change directory / takes you to the root directory ADMINISTERING DATABASES 49 Tip: The Linux file system is structured like a pyramid, with the Root directory at the top Starting from the Root directory, you can dig down into all the other directories, or folders, on the computer . STARTED WITH MYSQL 40 5. Type: exit then press ENTER. The Konsole window should close. GETTING STARTED WITH MYSQL 41 Giving MySQL commands to a Web server MySQL s. GETTING STARTED WITH MYSQL 39 4. Type: q; then press ENTER. This closes your MySQL database connection. You are now logged out of the MySQL server: the mysql& gt; prompt is. 44 Restart MySQL If you’ve shut off your computer since the last exercise, you might need to restart MySQL. First, login to your Linux computer as the Root user. Then restart the MySQL