天天看点

15个 MySQL 基础面试题,DBA 们准备好了吗?

15个 MySQL 基础面试题,DBA 们准备好了吗?

<a target="_blank"></a>

答案: debian 上运行命令 service mysql status,在redhat 上运行命令 service mysqld status。然后看看输出即可。

<code>root@localhost:/home/avi# service mysql status</code>

<code></code>

<code>/usr/bin/mysqladmin ver 8.42 distrib 5.1.72, for debian-linux-gnu on i486</code>

<code>copyright (c) 2000, 2013, oracle and/or its affiliates. all rights reserved.</code>

<code>oracle is a registered trademark of oracle corporation and/or its</code>

<code>affiliates. other names may be trademarks of their respective</code>

<code>owners.</code>

<code>server version 5.1.72-2</code>

<code>protocol version 10</code>

<code>connection localhost via unix socket</code>

<code>unix socket /var/run/mysqld/mysqld.sock</code>

<code>uptime: 1 hour 22 min 49 sec</code>

<code>threads: 1 questions: 112138 slow queries: 1 opens: 1485 flush tables: 1 open tables: 64 queries per second avg: 22.567.</code>

答案:运行命令 service mysqld start 开启服务;运行命令 service mysqld stop 停止服务。

<code>root@localhost:/home/avi# service mysql stop</code>

<code>stopping mysql database server: mysqld.</code>

<code>root@localhost:/home/avi# service mysql start</code>

<code>starting mysql database server: mysqld.</code>

<code>checking for corrupt, not cleanly closed and upgrade needing tables..</code>

答案:运行命令 mysql -u root -p

<code>root@localhost:/home/avi# mysql -u root -p</code>

<code>enter password:</code>

<code>welcome to the mysql monitor. commands end with ; or \g.</code>

<code>your mysql connection id is 207</code>

<code>server version: 5.1.72-2 (debian)</code>

<code>type 'help;' or '\h' for help. type '\c' to clear the current input statement.</code>

<code>mysql&gt;</code>

答案:运行命令 show databases;

<code>mysql&gt; show databases;</code>

<code>+--------------------+</code>

<code>| database |</code>

<code>| information_schema |</code>

<code>| a1 |</code>

<code>| cloud |</code>

<code>| mysql |</code>

<code>| phpmyadmin |</code>

<code>| playsms |</code>

<code>| sisso |</code>

<code>| test |</code>

<code>| ukolovnik |</code>

<code>| wordpress |</code>

<code>10 rows in set (0.14 sec)</code>

答案:运行命令 use database_name; 进入名为 database_name 的数据库。

<code>mysql&gt; use cloud;</code>

<code>reading table information for completion of table and column names</code>

<code>you can turn off this feature to get a quicker startup with -a</code>

<code>database changed</code>

答案:在当前数据库运行命令 show tables;

<code>mysql&gt; show tables;</code>

<code>+----------------------------+</code>

<code>| tables_in_cloud |</code>

<code>| oc_appconfig |</code>

<code>| oc_calendar_calendars |</code>

<code>| oc_calendar_objects |</code>

<code>| oc_calendar_repeat |</code>

<code>| oc_calendar_share_calendar |</code>

<code>| oc_calendar_share_event |</code>

<code>| oc_contacts_addressbooks |</code>

<code>| oc_contacts_cards |</code>

<code>| oc_fscache |</code>

<code>| oc_gallery_sharing |</code>

<code>10 rows in set (0.00 sec)</code>

答案:运行命令 describe table_name;

<code>mysql&gt; describe oc_users;</code>

<code>+----------+--------------+------+-----+---------+-------+</code>

<code>| field | type | null | key | default | extra |</code>

<code>| uid | varchar(64) | no | pri | | |</code>

<code>| password | varchar(255) | no | | | |</code>

<code>2 rows in set (0.00 sec)</code>

答案:运行命令 drop table table_name;

<code>mysql&gt; drop table lookup;</code>

<code>query ok, 0 rows affected (0.00 sec)</code>

答案:运行命令 drop database database-name;

<code>mysql&gt; drop database a1;</code>

<code>query ok, 11 rows affected (0.07 sec)</code>

答案:运行命令 select * from table_name;

<code>mysql&gt; select * from engines;</code>

<code>+------------+---------+----------------------------------------------------------------+--------------+------+------------+</code>

<code>| engine | support | comment | transactions | xa | savepoints |</code>

<code>| innodb | yes | supports transactions, row-level locking, and foreign keys | yes | yes | yes |</code>

<code>| mrg_myisam | yes | collection of identical myisam tables | no | no | no |</code>

<code>| blackhole | yes | /dev/null storage engine (anything you write to it disappears) | no | no | no |</code>

<code>| csv | yes | csv storage engine | no | no | no |</code>

<code>| memory | yes | hash based, stored in memory, useful for temporary tables | no | no | no |</code>

<code>| federated | no | federated mysql storage engine | null | null | null |</code>

<code>| archive | yes | archive storage engine | no | no | no |</code>

<code>| myisam | default | default engine as of mysql 3.23 with great performance | no | no | no |</code>

<code>8 rows in set (0.00 sec)</code>

答案:运行命令 select uid from oc_users;

<code>mysql&gt; select uid from oc_users;</code>

<code>+-----+</code>

<code>| uid |</code>

<code>| avi |</code>

<code>1 row in set (0.03 sec)</code>

答案:运行命令 select create_time, engine from xyz where engine = ”myisam”;

<code>mysql&gt; select create_time, engine from xyz where engine="myisam";</code>

<code>+---------------------+--------+</code>

<code>| create_time | engine |</code>

<code>| 2013-12-15 13:43:27 | myisam |</code>

<code>| 2013-10-23 14:56:38 | myisam |</code>

<code>132 rows in set (0.29 sec)</code>

答案:运行命令 select * from xrt where name = “tecmint” and web_address = “tecmint.com”;

<code>mysql&gt; select * from xrt where name = "tecmint" and web_address = “tecmint.com”;</code>

<code>+---------------+---------------------+---------------+</code>

<code>| id | name | web_address |</code>

<code>+---------------+---------------------+----------------+</code>

<code>| 13 | tecmint | tecmint.com |</code>

<code>| 41 | tecmint | tecmint.com |</code>

答案:运行命令 select * from xrt where name != "tecmint" and web_address = "tecmint.com";

<code>mysql&gt; select * from xrt where name != ”tecmint” and web_address = ”tecmint.com”;</code>

<code>| id | name | web_address |</code>

<code>| 1173 | tecmint | tecmint.com |</code>

答案:运行命令 select count(*) from table_name;

<code>mysql&gt; select count(*) from tables;</code>

<code>+----------+</code>

<code>| count(*) |</code>

<code>| 282 |</code>

<code>1 row in set (0.01 sec)</code>

以上是文章的全部内容。这篇‘linux 面试题’对您有任何帮助吗?别忘了在下面留言,写出您的宝贵意见。

原文发布时间为:2014-01-05

本文来自云栖社区合作伙伴“linux中国”