20131225-1 选题

This commit is contained in:
DeadFire 2013-12-25 09:49:13 +08:00
parent 6751a7f868
commit 1f862f8d6b
4 changed files with 571 additions and 0 deletions

View File

@ -0,0 +1,250 @@
15 Basic MySQL Interview Questions for Database Administrators
================================================================================
Prior to This Article, three articles has already been published in [Linux Interview][1] Section and all of them were highly appreciated by our notable readers, however we were receiving feedback to make this interactive learning process, section-wise. From idea to action, we are providing you **15 MySQL Interview Questions**.
![](http://www.tecmint.com/wp-content/uploads/2013/12/Mysql-Interview-Questions.png)
### 1. How would you check if MySql service is running or not? ###
> **Answer** : Issue the command “**service mysql status**” in Debian and “**service mysqld status**” in RedHat. Check the output, and all done.
root@localhost:/home/avi# service mysql status
/usr/bin/mysqladmin Ver 8.42 Distrib 5.1.72, for debian-linux-gnu on i486
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.1.72-2
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 hour 22 min 49 sec
Threads: 1 Questions: 112138 Slow queries: 1 Opens: 1485 Flush tables: 1 Open tables: 64 Queries per second avg: 22.567.
### 2. If the service is running/stop how would you stop/start the service? ###
> **Answer** : To start MySql service use command as **service mysqld start** and to stop use **service mysqld stop**.
root@localhost:/home/avi# service mysql stop
Stopping MySQL database server: mysqld.
root@localhost:/home/avi# service mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
### 3. How will you login to MySQL from Linux Shell? ###
> **Answer** : To connect or login to MySQL service, use command: **mysql -u root -p**.
root@localhost:/home/avi# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 207
Server version: 5.1.72-2 (Debian)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
### 4. How will you obtain list of all the databases? ###
> **Answer** : To list all currently running databases run the command on mysql shell as: **show databases**;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| a1 |
| cloud |
| mysql |
| phpmyadmin |
| playsms |
| sisso |
| test |
| ukolovnik |
| wordpress |
+--------------------+
10 rows in set (0.14 sec)
### 5. How will you switch to a database, and start working on that? ###
> **Answer** : To use or switch to a specific database run the command on mysql shell as: **use database_name**;
mysql> use cloud;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
### 6. How will you get the list of all the tables, in a database? ###
> **Answer** : To list all the tables of a database use the command on mysql shell as: **show tables**;
mysql> show tables;
+----------------------------+
| Tables_in_cloud |
+----------------------------+
| oc_appconfig |
| oc_calendar_calendars |
| oc_calendar_objects |
| oc_calendar_repeat |
| oc_calendar_share_calendar |
| oc_calendar_share_event |
| oc_contacts_addressbooks |
| oc_contacts_cards |
| oc_fscache |
| oc_gallery_sharing |
+----------------------------+
10 rows in set (0.00 sec)
### 7. How will you get the Field Name and Type of a MySql table? ###
> **Answer** : To get the Field Name and Type of a table use the command on mysql shell as: **describe table_name**;
mysql> describe oc_users;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| uid | varchar(64) | NO | PRI | | |
| password | varchar(255) | NO | | | |
+----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
### 8. How will you delete a table? ###
> **Answer** : To delte a specific table use the command on mysql shell as: **drop table table_name**;
mysql> drop table lookup;
Query OK, 0 rows affected (0.00 sec)
### 9. What about database? How will you delete a database? ###
> **Answer** : To delte a specific database use the command on mysql shell as: **drop database database-name**;
mysql> drop database a1;
Query OK, 11 rows affected (0.07 sec)
### 10. How will you see all the contents of a table? ###
> **Answer** : To view all the contents of a particular table use the command on mysql shell as: **select * from table_name**;
mysql> select * from engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ENGINE | SUPPORT | COMMENT | TRANSACTIONS | XA | SAVEPOINTS |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
### 11. How will you see all the data in a field (say, uid), from table (say, oc_users)? ###
> **Answer** : To view all the data in a field use the command on mysql shell as: **select uid from oc_users**;
mysql> select uid from oc_users;
+-----+
| uid |
+-----+
| avi |
+-----+
1 row in set (0.03 sec)
### 12. Say you have a table xyz, which contains several fields including create_time and engine. The field engine is populated with two types of data Memory and MyIsam. How will you get only create_time and engine from the table where engine is MyIsam? ###
> **Answer** : Use the command on mysql shell as: **select create_time, engine from xyz where engine=”MyIsam”**;
mysql> select create_time, engine from xyz where engine="MyIsam";
+---------------------+--------+
| create_time | engine |
+---------------------+--------+
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
+---------------------+--------+
132 rows in set (0.29 sec)
### 13. How will you show all the records from table xrt where name is tecmint and web_address is tecmint.com? ###
> **Answer** : Use the command on mysql shell as: **select * from xrt where name = “tecmint” and web_address = “tecmint.com”**;
mysql> select * from xrt where name = "tecmint" and web_address = “tecmint.com”;
+---------------+---------------------+---------------+
| Id | name | web_address |
+---------------+---------------------+----------------+
| 13 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
| 41 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
### 14. How will you show all the records from table xrt where name is not tecmint and web_address is tecmint.com? ###
> **Answer** : Use the command on mysql shell as: **select * from xrt where name != “tecmint” and web_address = “tecmint.com”**;
mysql> select * from xrt where name != ”tecmint” and web_address = ”tecmint.com”;
+---------------+---------------------+---------------+
| Id | name | web_address |
+---------------+---------------------+----------------+
| 1173 | tecmint | tecmint.com |
+---------------+---------------------+----------------+
### 15. You need to know total number of row entry in a table. How will you achieve it? ###
> **Answer** : Use the command on mysql shell as: **select count(*) from table_name**;
mysql> select count(*) from Tables;
+----------+
| count(*) |
+----------+
| 282 |
+----------+
1 row in set (0.01 sec)
Thats all for now. How you feel about this **Linux Interview Question** section. Dont forget to provide us with your valuable feedback in our comment section.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/basic-mysql-interview-questions-for-database-administrators/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.tecmint.com/category/interview-questions/

View File

@ -0,0 +1,105 @@
Linux id Command Print user ID and group ID information
================================================================================
To log in into a computer, we need a username. Username is an identity to recognized by a computer. Based on it, computer will apply a set of rules to a someone that log in with that username. On Linux system we can use **id** command.
### What is id command ###
**id** command is command which can print real and effective User ID (UID) and Group ID (GID). An UID is a single identity for a user. While Group ID (GID) can consist more than one UID.
### How to use it ###
By default, **id** command is installed on most of Linux system. To use it, just type id on your console. Typing id without no options will result as below. The result will use the active user.
$ id
![Default id output](http://linoxide.com/wp-content/uploads/2013/12/id_default.png)
#### Heres how to read the output : ####
- User **pungki** has **UID** number = **1000**, **GID** number = **1000**
- User **pungki is a member** of the following groups :
**pungki** with GID = **1000**
**adm** with GID = **4**
**cdrom** with GID = **24**
**sudo** with GID = **27**
**dip** with GID = **30**
**plugdev** with GID = **46**
**lpadmin** with GID = **108**
**sambashare** with GID = **124**
### Using id with options ###
There are some options that can applied to id command. Heres some options that may useful on day-to-day basis.
#### Print user name, UID an all the group to which the user belongs ####
To do this, we can use **-a** option
$ id -a
![-a option](http://linoxide.com/wp-content/uploads/2013/12/id_a.png)
#### Output all different group IDs (effective, real and supplementary) ####
We can use **-G** option to do fulfill this.
$ id -G
![-G option](http://linoxide.com/wp-content/uploads/2013/12/id_G.png)
The result will only show the GID numbers. You can compare it with **/etc/group** file. Heres a sample of **/etc/grou**p content :
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:pungki
fax:x:21:
voice:x:22:
cdrom:x:24:pungki
floppy:x:25:
tape:x:26:
sudo:x:27:pungki
audio:x:29:pulse
dip:x:30:pungki
www-data:x:33:
backup:x:34:
operator:x:37:
sasl:x:45:
plugdev:x:46:pungki
ssl-cert:x:107:
lpadmin:x:108:pungki
saned:x:123:
sambashare:x:124:pungki
winbindd_priv:x:125:
#### Output only the effective group ID ####
Use **-g** option to output only the effective group ID
$ id -g
![-g option](http://linoxide.com/wp-content/uploads/2013/12/id_g1.png)
#### Print the specific user information ####
We can output a specific user information related UID and GID. Just put the user name after id command.
$ id leni
![leni user](http://linoxide.com/wp-content/uploads/2013/12/id_leni.png)
Above command will print UID and GID of user named **leni**.
### Conclusion ###
This id command is useful for us when we want to know about UID and GID of a user. Some applications may need UID / GID to be run. id make us easier to find UID and GID of a user without seeing and searching it inside /etc/group file. As usual you can go to id manual page by typing **man id** from your console to explore more detail.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-id-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,110 @@
Linux iostat Command to Report CPU Statistics and I/O Statistics
================================================================================
A Central Processing Unit or CPU is the brain of the computer. All of processing command is run here. Input / Ouput or I/O also play critical roles. The disks is used to provide data to processor and keeps the data which has been processed by CPU. One of the methods for measuring processor utilization and I/O utilization is to use **iostat** command. From its utilization we can decide do we need to add more resources or not.
### What is iostat ###
iostat command is a command that used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat create reports that can be used to change system configuration to better balance the input/output between physical disks.
### Installing iostat ###
iostat is included in **sysstat** package. If you dont have it, you need to install first.
#### On RedHat / CentOS / Fedora ####
# yum install sysstat
#### On Debian / Ubuntu / Linux Mint ####
$ sudo apt-get install sysstat
#### How to run iostat ####
To run it, just **type iostat** in your console. Heres a sample.
$ iostat
![iostat default report](http://linoxide.com/wp-content/uploads/2013/12/iostat_default.png)
#### Heres how to read iostat reports ####
#### The first section contains CPU report ####
- **%user** : show the percentage of CPU utilization that occured while executing at the user (application) level
- **%nice** : show the percentage of CPU utilization that occured while executing at the user level with nice priority
- **%system** : show the percentage of CPU utilization that occured while executing at the system (kernel) level
- **%iowait** : show the percentage of the time that the CPU or CPUs were idle during whcih the system had an outstanding disk I/O request
- **%steal** : show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor
- **%idle** : show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request
#### The second section contains device utilization report ####
- **Device** : device / partition name as listed in **/dev** directory
- **tps** : show the number of transfers per second that were issued to the device. Higher tps means the processor is busier
- **Blk_read/s** : show the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second
- **Blk_wrtn/s** : show the amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second
- **Blk_read** : show the total number of blocks read
- **Blk_wrtn** : show the total number of blocks written
### Capture iostat with kilobytes or megabytes ###
By default iostat measure the I/O system with bytes unit. To make it easier to read, we can convert iostat to show us reports in kilobytes or megabytes unit. Just add **-k parameter** to create reports with **kilobytes unit** and **-m parameter** to create reports with **megabytes unit**.
$ iostat -k
![iostat with kilobytes](http://linoxide.com/wp-content/uploads/2013/12/iostat_k.png)
$ iostat -m
![iostat megabytes unit](http://linoxide.com/wp-content/uploads/2013/12/iostat_m.png)
To extend the reports we can use **-x parameter** after iostat command.
$ iostat -x
![extend iostat report](http://linoxide.com/wp-content/uploads/2013/12/iostat_x.png)
### Using iostat with delay ###
Same with [vmstat][1], as a statistic tool the best way to use it is with delay parameter. With delay, we can see whats the trend. Here are some samples to run iostat with delay.
#### Run iostat with kilobytes unit, 2 seconds interval with 3 times reports ####
$ iostat -k 2 3
![iostat reports in kilobytes](http://linoxide.com/wp-content/uploads/2013/12/iostat_k_2_3.png)
#### Show CPU only report with 3 seconds interval and 6 times reports ####
$ iostat -c 3 6
![iostat cpu only with delay 3 seoncds](http://linoxide.com/wp-content/uploads/2013/12/iostat_c_3_6.png)
#### Show hda2 and hda6 device only report with 2 seconds interval and 4 times reports ####
$ iostat -d hda2 hda6 2 4
![iostat disk only](http://linoxide.com/wp-content/uploads/2013/12/iostat_d_hda2_hda6_2_4.png)
### Files ###
iostat use these files to create reports.
**/proc/stat** which contains system statistics
**/proc/partitions** which contains disk statistics (for pre 2.5 kernel that have been patched)
**/proc/diskstats** contains disks statistics (for post 2.5 kernel)
**/sys** which contains statistics for block devices (post 2.5 kernel)
### Conclusion ###
With vmstat to monitor memory usage, iostat to monitor CPU usage and I/O system then we have a complete tool to monitor three critical components in your machine. One of the advantage of those tools is you can run them without root privilege. You can dig it deeper by exploring iostat manual page. Just type **man iostat** in your console to bring iostat manual page.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-iostat-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/

View File

@ -0,0 +1,106 @@
Linux vmstat Command Tool to Report Virtual Memory Statistics
================================================================================
As we already know that computer must have memory which called RAM to make the computer works. RAM is refer to a physical memory that planted into the computer mainboard. This RAM is used to load applications such as browser, word processor and so on. So actually, programs that you are using are running on the memory.
Let say you have 2 GB of memory. When you are running an operating system, it may that your available memory is only 1,5 GB. Then you actively using a lot of applications. When the usage of the memory is full, you can load more applications anymore. In plain English, the computer may say “Sorry, you can not run more applications, please close some programs if you would like to run more applications”
To solve this problem, operating system including Linux use a method named Virtual Memory. This method will search the area of memory which not used recently by any applications, then copy it into computer harddisk. This can give some free memory area and give you chance to run more applications.
To monitor this virtual memory activities, we can use **vmstat** tool.
### What is vmstat ###
Vmstat is a tool that provide reporting virtual memory statistics. It covers systems memory, swap and processors utilizations in real time.
### How to run vmstat ###
Same with [mpstat][1], vmstat is included inside sysstat package. If you dont have it, please install sysstat package.
To run vmstat, just type vmstat in your console. Running vmstat without parameter will show you a default result of vmstat.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_default.png)
Lets see how to read the information provided by vmstat :
### Procs ###
Procs have **r** column and **b** column. **r** columns means the total number of processes that waiting access fot the processor. While b column means the total no processes in a sleep state. Below those columns, there are values. From the above screenshot, we have 2 processes that waiting access to the processor and 0 for sleep processes.
### Memory ###
Memory have **swpd, free, buff** and **cache** columns. This information is the same with **free -m** command. The **swpd column** show you about how much memory has been swapped to a swap file or disk. The **free column** show you the unallocated memory available. **Buff column** means how much in use memory. And **cache column** show you about how much memory that can be swapped into swap file or disk if there are some application is needed by them.
### Swap ###
Swap show us how much memory is sent or retrieved from the swap system. The **si** column tell us how much memory is moved **from swap to real memory** per second. The so column tell us how much memory that is moved **from real memory to swap**.
### I/O ###
The **io** show us the amount of input and output activity per second in terms of blocks read and blocks written. The **bi** column tell us about the number of blocks received and the **bo** tell us about the number of blocks sent.
### System ###
System show us the number of system operations per second. The **in** column tell us about the number system interrupts per second. The **cs** column tell us the number of context switches that the system makes in order to process all tasks.
### CPU ###
CPU show us the use of CPUs resources. The **us column** tell us how much time that processor spends on non-kernel processes. The **sy column** tell us about how much time that processor spends on kernel related tasks. The **id column** tell us about how long the processor are idle. The **wa column** tell us how much time that the processor has been waiting for I/O operations to complete before being able to continue processing tasks.
### Using vmstat with delay ###
As a tool for statistics, the best way of using vmstat is using a **delay**. So you can capture the activity periodically. Let say we want to run vmstat with 5 second delay. Just type **vmstat 5** on your console to do it.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_delay_5.png)
The command will run every 5 seconds **until** you press Ctrl-C to stop it.
You can use **count** to limit how many times vmstat will running.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_count_7.png)
The above command will run **vmstat with 5 seconds delay for 7 times**.
### Show active and inactive memory ###
To do it, you can add **-a** parameter to vmstat. Heres a sample.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_a.png)
### Show summarize disk statistics ###
vmstat can print your system disk statistics if you want. Use **-D** parameter to print it.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_disk_sum.png)
### Show display unit ###
You can choose what unit character you want to print. Use **-S followed by k (1000), K (1024), m (1000000), M (1048576)** bytes. If you dont choose the unit, vmstat will use K (1024).
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_define_unit.png)
### Print detail statistics for specific partition ###
To do it, you can use **-p parameter followed by device name**. Heres an example of it.
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_partition.png)
### Files ###
vmstat is using these files to works.
/proc/meminfo
/proc/stat
/proc/*/stat
### Conclusion ###
If you feel your system is running out memory, before you add some physical memory, this tool can help you to determine the root cause of the problem. As usual, you can explore more detail about vmstat command by typing **man vmstat** on your console. It will bring you to vmstat manual page.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/linux-mpstat-command/