20070316a

From Wsms

Jump to: navigation, search

previous next
GO TO:
Parent class notes: MySQL class notes
Angelica's complementary notes



Friday March 16 2007

Contents

Quiz 28

See: http://wsms.wikiplanet.com/html/quiz/quiz28-20070316.html

Question 1

(25 points)

What is the format of the mysqldump command that will:

  • Create the appropriate SQL commands to create and populate all the tables from the sample database?
  • Store these commands in a file called sample.sql in the current working directory?
mysqldump -u root -p sample > sample.sql

Question 2

(25 points)

Run this command to generate the file sample.sql

You do that with the shell in Windows. Duh.

Question 3

(25 points)

Transfer this file to your Linux Virtual machine. Remember to restart your networking and check your IP address on the Virtual Machine so that you are not inadvertently using your classmate's computer!

On the Linux virtual machine:

[root@ws05 ~]# service network restart
Shutting down interface eth0:  Device eth0 has MAC address 00:0C:29:6D:F1:AA, instead of configured address 00:0C:29:28:99:D0. Ignoring.
                                                           [FAILED]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:
Determining IP information for eth0...dhclient(1428) is already running - exiting.
exiting.
 failed.
[root@ws05 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:6D:F1:AA
          inet addr:10.101.20.58  Bcast:10.101.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe6d:f1aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:668298 errors:0 dropped:0 overruns:0 frame:0
          TX packets:498717 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:572068473 (545.5 MiB)  TX bytes:53128631 (50.6 MiB)
          Interrupt:177 Base address:0x1400

So, you see the IP address is 10.101.20.58. On the Windows side, use SSH Secure Shell and open a connect to that address. Then transfer the sample.sql file to a convenient location.

Question 4

(25 points)

Use the file to populate a database on Linux called sample with the same data as on Windows.

Back on the Linux side:

[ggeller@ws05 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.0.27

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database sample;
Query OK, 1 row affected (0.00 sec)

mysql> use sample;
Database changed
mysql> source sample.sql
...
mysql> show tables;
+------------------+
| Tables_in_sample |
+------------------+
| absence          |
| articles         |
| grade_event      |
| huck_finn_lines  |
| member           |
| president        |
| prez_name        |
| score            |
| student          |
+------------------+
9 rows in set (0.00 sec)

unix versus msdos text file format

Unix text files have line terminators that are just one character, the CR (carriage return aka newline aka \n). Dos text file have line terminators that are two characters, CRLF (carriage return-line feed). SSH Secure Shell does the conversion for you if:

  • You have the text format button selected.
  • Or, you have to auto button select that the file extension is one of those recognized by SSH Secure Shell as a text file.

Here is a screen dump of SSH Secure Shell with the auto format button selectect:
Image:20070316-0920-ssh-secure-shell.png
One a file is on your Linux system you can use the file command to determine file type and you can use unix2dos and dos2unix to convert text file.

[ggeller@ws05 sampdb]$ file sample.sql
sample.sql: ASCII English text, with very long lines
[ggeller@ws05 sampdb]$ unix2dos sample.sql
unix2dos: converting file sample.sql to DOS format ...
[ggeller@ws05 sampdb]$ file sample.sql
sample.sql: ASCII English text, with very long lines, with CRLF line terminators

mysqldump

see mysqldump

webmin and usermin

Then we learned how to use webmin to creat an new mysql user and usermin to administer that database as the user. In case you forgot, webmin is at http://localhost:1000 and usermin is at http://localhost:2000. If you need to access webmin on other than localhost, use ssh to forward the port.

Personal tools