Mysql面试问题
1.如何检查MySql服务是否正在运行?
答:
在发出“Debian的”在redhat命令“的服务mysql的地位 ”,“ 服务mysqld的状态 。”
检查输出,并完成。
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.如果服务正在运行/停止,您将如何停止/启动服务?
答:
要启动MySQL服务使用命令服务mysqld的启动和停止使用服务的mysqld停止 。
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.你将如何从Linux Shell登录MySQL?
答:
要连接或登录到MySQL服务,使用命令:mysql的- ü根-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.你将如何获得所有数据库的列表?
答:
要列出所有正在运行的数据库上运行mysql外壳的命令:show数据库;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a1 | | cloud | | mysql | | phpmyadmin | | playsms | | sisso | | test | | ukolovnik | | wordpress | +--------------------+ 10 rows in set (0.14 sec)
5.如何切换到数据库,并开始工作?
答:
要使用或切换到一个特定的数据库上mysql外壳运行命令为: 使用数据库名称;
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.如何在数据库中获取所有表的列表?
答:
要列出一个数据库中所有表上mysql外壳使用命令: 节目表;
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.如何获取MySql表的字段名称和类型?
答:
要获得字段名和表的类型上使用mysql外壳的命令: 形容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.如何删除表?
答:
要delte特定表使用命令在mysql外壳为:DROP TABLE TABLE_NAME;
mysql> drop table lookup; Query OK, 0 rows affected (0.00 sec)
9.数据库呢?如何删除数据库?
答:
要delte特定数据库使用命令在mysql外壳为:DROP DATABASE数据库名称;
mysql> drop database a1; Query OK, 11 rows affected (0.07 sec)
10.你将如何看到表的所有内容?
答:
要查看特定表的所有内容上mysql外壳使用命令: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.你将如何在表(例如,oc_users)中看到字段(比如,uid)中的所有数据?
答:
要查看所有在外地的mysql外壳为使用该命令的数据: 从oc_users选择UID;
mysql> select uid from oc_users; +-----+ | uid | +-----+ | avi | +-----+ 1 row in set (0.03 sec)
假设你有一个表'xyz',它包含几个字段,包括'create_time'和'engine'。字段“engine”被填充两种类型的数据“Memory”和“MyIsam”。如何从引擎是“MyIsam”的表中只获取“create_time”和“engine”?
答:
在mysql外壳为使用命令: 选择CREATE_TIME,发动机从XYZ那里发动机=“MyISAM数据”;
12. 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.如何显示表'xrt'中名称为“youcl”和web_address为“youcl.com”的所有记录?
答:
关于mysql外壳使用命令: 从XRT其中name =“youcl”和WEB_ADDRESS =“youcl.com”SELECT *;
mysql> select * from xrt where name = "youcl" and web_address = “youcl.com”; +---------------+---------------------+---------------+ | Id | name | web_address | +---------------+---------------------+----------------+ | 13 | youcl | youcl.com | +---------------+---------------------+----------------+ | 41 | youcl | youcl.com | +---------------+---------------------+----------------+
14.如何显示表'xrt'中名称不是“youcl”和web_address是“youcl.com”的所有记录?
答:
关于mysql外壳使用命令: 从XRT选择*其中名称=“youcl”和WEB_ADDRESS =“youcl.com!”;
mysql> select * from xrt where name != ”youcl” and web_address = ”youcl.com”; +---------------+---------------------+---------------+ | Id | name | web_address | +---------------+---------------------+----------------+ | 1173 | youcl | youcl.com | +---------------+---------------------+----------------+
15.您需要知道表中的行条目总数。你将如何实现呢?
答:
在mysql外壳为使用命令: 从TABLE_NAME SELECT COUNT(*);
mysql> select count(*) from Tables; +----------+ | count(*) | +----------+ | 282 | +----------+ 1 row in set (0.01 sec)另请阅读 : 10 MySQL数据库面试问题中间体 目前为止就这样了。你如何看待这个 “Linux的面试问题 ”一节。不要忘记在我们的评论部分向我们提供您的宝贵反馈。