当前位置:   article > 正文

MySql数据库面试题_mysql 数据库 面试题

mysql 数据库 面试题

1 用select语句找到当前服务器版本,当前数据库

mysql> SELECT VERSION(), DATABASE();

+-------------------------+------------+
| VERSION()               | DATABASE() |
+-------------------------+------------+
| 5.5.34-0ubuntu0.13.10.1 | NULL       |
+-------------------------+------------+
1 row in set (0.06 sec)

mysql> use Tecmint;
mysql> select VERSION(), DATABASE();

+-------------------------+------------+
| VERSION()               | DATABASE() |
+-------------------------+------------+
| 5.5.34-0ubuntu0.13.10.1 | tecmint    |
+-------------------------+------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2 使用not操作符(!),显示tecmint表,除用户sam的所有用户

mysql> SELECT * FROM Tecmint WHERE user !=SAM;

+---------------------+---------+---------+---------+---------+-------+ 
| date                | user    | host 	 | root     | local   | size  | 
+---------------------+---------+---------+---------+---------+-------+ 
| 2001-05-14 14:42:21 | Anthony | venus  | barb     | venus   | 98151 | 
| 2001-05-15 08:50:57 | TIM     | venus  | phil     | venus   | 978   | 
+---------------------+---------+---------+---------+---------+-------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3 请简要说明ifnull()用法
ifnull 用来检查返回列的值(第一个参数),是否存在,如果存在返回,不存在返回第二个参数设定的值

mysql> SELECT name, IFNULL(id,'Unknown') AS 'id' FROM taxpayer;

+---------+---------+ 
| name 	  | id      | 
+---------+---------+ 
| bernina | 198-48  | 
| bertha  | Unknown | 
| ben     | Unknown | 
| bill    | 475-83  | 
+---------+---------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

4 返回指定的行数,从结果集的开始或末尾

mysql> SELECT * FROM profile LIMIT 5;

+----+------+------------+-------+-----------------------+------+ 
| id | name | birth      | color | foods                 | cats | 
+----+------+------------+-------+-----------------------+------+ 
| 1  | Fred | 1970-04-13 | black | lutefisk,fadge,pizza  | 0    | 
| 2  | Mort | 1969-09-30 | white | burrito,curry,eggroll | 3    | 
| 3  | Brit | 1957-12-01 | red   | burrito,curry,pizza   | 1    |   
| 4  | Carl | 1973-11-02 | red   | eggroll,pizza         | 4    | 
| 5  | Sean | 1963-07-04 | blue  | burrito,curry         | 5    | 
+----+------+------------+-------+-----------------------+------+

mysql> SELECT * FROM profile order by bither LIMIT 1;
+----+------+------------+-------+----------------+------+ 
| id | name | birth      | color | foods          | cats | 
+----+------+------------+-------+----------------+------+ 
| 9  | Dick | 1952-08-20 | green | lutefisk,fadge | 0    | 
+----+------+------------+-------+----------------+------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

5 oracle 和 mysql哪个更好一点,如何选
各有有点。但我喜欢mysql
mysql
1开源 2 可移动端运用 3支持gui和command 4支持querybrowse

6 获取mysql日期

mysql> SELECT CURRENT_DATE();

+----------------+
| CURRENT_DATE() |
+----------------+
| 2014-06-17     |
+----------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

7 用mysql将指定表导出xml文件

mysql -u USER_NAME –xml -e 'SELECT * FROM table_name' > table_name.xml
  • 1

8 简介MySQL_pconnect,他与MySQL_connect有什么不同
MySQL_pconnect是建立数据库连接并保持持续性,不能用mysql_close关闭,mysql_connect没有这个特性,所以可以用MySQL_close()关闭

9 检索一个user表的所有索引

mysql> show index from user;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| user  |          0 | PRIMARY  |            1 | Host        | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               | 
| user  |          0 | PRIMARY  |            2 | User        | A         |           4 |     NULL | NULL   |      | BTREE      |         |               | 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
2 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

10 什么是csv表
csv是一个标准。通常使用逗号分割字段,用文本存储数据。通常一行一个记录。除了用逗号,也可以用其他指定符号分割字段。

11 mysql是否运行,并确认状态,如何启动并停止

# service mysql status | start | stop
# sytemctl status | start | stop  mysql
  • 1
  • 2

12 linuxshell 登录mysql

# mysql -u root -p 
  • 1

13 检查服务器中的数据库,切换数据库, 显示数据库的所有表

mysql> show databases;
mysql> use cloud; 
mysql> show tables; 
  • 1
  • 2
  • 3

14 查看某个数据表的结构

mysql> describe table1; 
  • 1

15 删除数据库,删除数据表

mysql> drop database db1; 
mysql> drop table tb1; 
  • 1
  • 2

16 获的表的所有记录总数

mysql> select count(*) from Tables; 
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/639612
推荐阅读
相关标签
  

闽ICP备14008679号