mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Merge pull request #1293 from johnhoow/master
translated "11 Advance MySQL Database 'Interview Questions and Answers' for Linux Users"
This commit is contained in:
commit
6905e3fa99
@ -1,4 +1,3 @@
|
||||
translating by johnhoow...
|
||||
给linux用户的11个高级MySQL数据库面试问题和答案
|
||||
================================================================================
|
||||
我们已经发表了两篇MySQL的文章,非常感谢Tecmint社区的大力支持.这是MySQL面试系列的第三篇文章,并且在面试专栏中排第16.
|
||||
@ -10,7 +9,7 @@ translating by johnhoow...
|
||||
感谢你们这一路上对我们的支持.这篇文章主要针对MySQL的实用性,讲面试方面的问题.
|
||||
|
||||
### 1. 如何使用SELECT语句找到你正在运行的服务器的版本并打印出当前数据库的名称? ###
|
||||
**答案**:下面的语句的结果会显示服务器的版本和当前的数据库名称
|
||||
**Ans**:下面的语句的结果会显示服务器的版本和当前的数据库名称
|
||||
|
||||
mysql> SELECT VERSION(), DATABASE();
|
||||
|
||||
@ -43,7 +42,7 @@ translating by johnhoow...
|
||||
|
||||
### 2. 使用非运算符(!)从表"Tecmint"中列出除了user等于"SAM"的所有记录
|
||||
|
||||
**答案**:使用下面的语句
|
||||
**Ans**:使用下面的语句
|
||||
|
||||
mysql> SELECT * FROM Tecmint WHERE user !=SAM;
|
||||
|
||||
@ -56,12 +55,11 @@ translating by johnhoow...
|
||||
|
||||
### 3. 是否能够使用非运算符(!)来实现'AND'运算
|
||||
|
||||
**答案**: The AND operator is used when we use (=) and the operator OR is used when we use (!=). An example of (=) with AND Operator.
|
||||
**答案**:
|
||||
**Ans**: 我们使用’=’号和OR运算符或者'!='和AND运算符,下面是'='和AND运算符的例子
|
||||
|
||||
mysql> SELECT * FROM mail WHERE user = SAM AND root = phil
|
||||
|
||||
An Example of (!=) with OR Operator.
|
||||
'!='和OR运算符的例子
|
||||
|
||||
mysql> SELECT * FROM mail WHERE user != SAM OR root != phil
|
||||
|
||||
@ -71,15 +69,15 @@ An Example of (!=) with OR Operator.
|
||||
| 2001-05-14 14:42:21 | Anthony | venus | barb | venus | 98151 |
|
||||
+---------------------+---------+---------+---------+---------+-------+
|
||||
|
||||
- = : means Equal to
|
||||
- != : Not Equal to
|
||||
- ! : represents NOT Operator
|
||||
- = : 等于
|
||||
- != : 不等于
|
||||
- ! : 非运算符
|
||||
|
||||
The AND & OR are treated as joining operators in MySQL.
|
||||
AND和OR在MySQL中被看作加入运算符
|
||||
|
||||
### 4. What IFNULL() statement is used for in MySQL? ###
|
||||
### 4. IFNULL()语句在MySQL中有什么作用? ###
|
||||
|
||||
**Ans**: The Query in MySQL can be written precisely using **IFNULL()** statement. The IFNULL() statement test its first argument and returns if it’s not NULL, or returns its second argument, otherwise.
|
||||
**Ans**: **IFNULL**语句的使用使得MySQL中的查询更加精确。IFNULL()语句先测试它的的一个参数,若不为空就返回该参数的值,否则返回第二个参数的值
|
||||
|
||||
mysql> SELECT name, IFNULL(id,'Unknown') AS 'id' FROM taxpayer;
|
||||
|
||||
@ -92,11 +90,11 @@ The AND & OR are treated as joining operators in MySQL.
|
||||
| bill | 475-83 |
|
||||
+---------+---------+
|
||||
|
||||
### 5. You want to see only certain rows from a result set from the beginning or end of a result set. How will you do it? ###
|
||||
### 5. 如果你只想知道从一个结果集的开头或者结尾开始的特定条数的行记录改如何实现?
|
||||
|
||||
**Ans**: We need to use **LIMIT** clause along with ORDER BY to achieve the above described scenario.
|
||||
**Ans**: 我们可以用**LIMIT**和**ORDER BY**从句。
|
||||
|
||||
#### Show 1 Record ####
|
||||
#### 显示一行记录 ####
|
||||
|
||||
mysql> SELECT * FROM name LIMIT 1;
|
||||
|
||||
@ -106,7 +104,7 @@ The AND & OR are treated as joining operators in MySQL.
|
||||
| 1 | Fred | 1970-04-13 | black | lutefisk,fadge,pizza | 0 |
|
||||
+----+------+------------+-------+----------------------+------+
|
||||
|
||||
#### Show 5 Record ####
|
||||
#### 显示5行记录 ####
|
||||
|
||||
mysql> SELECT * FROM profile LIMIT 5;
|
||||
|
||||
@ -120,7 +118,7 @@ The AND & OR are treated as joining operators in MySQL.
|
||||
| 5 | Sean | 1963-07-04 | blue | burrito,curry | 5 |
|
||||
+----+------+------------+-------+-----------------------+------+
|
||||
|
||||
----------
|
||||
#### 显示按照ORDER BY排序后的第一条记录 ####
|
||||
|
||||
mysql> SELECT * FROM profile ORDER BY birth LIMIT 1;
|
||||
|
||||
@ -130,20 +128,20 @@ The AND & OR are treated as joining operators in MySQL.
|
||||
| 9 | Dick | 1952-08-20 | green | lutefisk,fadge | 0 |
|
||||
+----+------+------------+-------+----------------+------+
|
||||
|
||||
### 6. Oracle Vs MySQL. Which one and Why? ###
|
||||
### 6. Oracle 和 MySQL该如何选择? ###
|
||||
|
||||
**Ans**: Well both has its advantages and disadvantages. As a matter of time I prefer MySQL.
|
||||
**Ans**: 它们都有各自的优点和缺点。
|
||||
|
||||
#### Reason for Selection MySQL Over oracle ####
|
||||
#### 选择MySQL而不选orcale的原因 ####
|
||||
|
||||
- Mysql is FOSS.
|
||||
- MySQL is portable.
|
||||
- MYSQL supports both GUI as well as Command Prompt.
|
||||
- MySQL Administration is supported over Query Browser.
|
||||
- 开源
|
||||
- 轻便快捷
|
||||
- 有命令行和图形界面
|
||||
- 能通过查询器进行数据库的管理
|
||||
|
||||
### 7. How will you get current date in MySQL? ###
|
||||
### 7. MySQL中如何得到当前日期? ###
|
||||
|
||||
**Ans**: Getting current date in MySQL is as simple as executing the below SELECT Statement.
|
||||
**Ans**: 使用CURRENT_DATE()函数
|
||||
|
||||
mysql> SELECT CURRENT_DATE();
|
||||
|
||||
@ -153,26 +151,25 @@ The AND & OR are treated as joining operators in MySQL.
|
||||
| 2014-06-17 |
|
||||
+----------------+
|
||||
|
||||
### 8. How will you export tables as an XML file in MySQL? ###
|
||||
### 8. MySQL中如何将表导出为XML文件? ###
|
||||
|
||||
**Ans**: We use ‘-e‘ (export) option to export MySQL table or the whole database into an XML file. With large tables we may need to implement it manually but for small tables, applications like phpMyAdmin can do the job.
|
||||
A native command of MySQL can do it.
|
||||
**Ans**: 使用'-e'(export)参数来把MySQL表或整个数据库导出到XML文件。当处理大型表的时候或许我们需要手动导出,但是只是导出小文件的话可以直接使用想phpMyAdmin这样的工具。
|
||||
|
||||
mysql -u USER_NAME –xml -e 'SELECT * FROM table_name' > table_name.xml
|
||||
|
||||
Where USER_NAME is username of Database, table_name is the table we are exporting to XML and table_name.xml is the xml file where data is stored.
|
||||
上面的例子中USER_NAME是数据库的用户名,table_name是待导出为xml文件的表名,table_name.xml是存放数据的xml文件
|
||||
|
||||
### 9. What is MySQL_pconnect? And how it differs from MySQL_connect? ###
|
||||
### 9. MySQL_pconnect是什么? 它和MySQL_connect有什么区别? ###
|
||||
|
||||
**Ans**: MySQL_pconnect() opens a connection that is persistent to the MySQL Database which simply means that the database is not opened every-time the page loads and hence we can not use MySQL_close() to close a persistent connection.
|
||||
**Ans**: MySQL_pconnect()打开一个永久的数据库连接,这意味着数据库不是在每次页面加载的时候被打开,因此我们不能使用MySQL_close()来关闭一个永久的连接
|
||||
|
||||
A brief difference between MySQL_pconnect and MySQL_connect are.
|
||||
MySQL_pconnect和MySQL_connect有一定的差别
|
||||
|
||||
Unlike MySQL_pconnect, MySQL_connect – Opens the Database every-time the page is loaded which can be closed any-time using statement MySQL_close().
|
||||
和MySQL_pconnect不同,MySQL_connect在每次页面被加载的时候打开,并且可以使用MySQL_close()语句来关闭连接
|
||||
|
||||
### 10. You need to show all the indexes defined in a table say ‘user’ of Database say ‘mysql’. How will you achieve this? ###
|
||||
### 10. 如何查看一个名为'mysql'的数据库中'user'表中的所有索引? ###
|
||||
|
||||
**Ans**: The following command will show all the indexes of a table ‘user’.
|
||||
**Ans**: 可以使用下面的语句
|
||||
|
||||
mysql> show index from user;
|
||||
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|
||||
@ -183,13 +180,13 @@ Unlike MySQL_pconnect, MySQL_connect – Opens the Database every-time the page
|
||||
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|
||||
2 rows in set (0.00 sec)
|
||||
|
||||
### 11. What are CSV tables? ###
|
||||
### 11. 什么是CSV表? ###
|
||||
|
||||
**Ans**: CSV stands for Comma-Separated Values aka Character-Separated Values. CSV table stores data in plain text and tabular format. It typically contains one record per line.
|
||||
**Ans**: CSV是逗号分隔值的缩写,也称为字符分隔值。CSV表中存放纯文本和表格数据。
|
||||
|
||||
Each record is separated by specific delimiters (Comma, Semi-colon, …) where each record has same sequence of field. CSV tables are most widely used to store phone contacts to Import and Export and can be used to store any sort of plain text data.
|
||||
每一条记录使用具体的分隔符隔开(如逗号,分号,...),CSV表广泛的用来存放易于导入和导出的电话联系人,能够用来存放任何数量的纯文本。
|
||||
|
||||
That’s all for now. I’ll be here again with another Interesting article, you people will love to read. Till then stay tuned and connected to Tecmint and Don’t forget to provide us with your valuable feedback in the comment section below.
|
||||
以上就是这次要将的内容。我还会带来其他的有趣的文章,向往你们喜欢。连接到Tecmint继续关注我们,不要忘了在评论栏中留下你们的宝贵意见。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user