MySQL Basic question

Source: Internet
Author: User

Question 1: How do you determine if MySQL is running?

answer : Run command service mysql statuson Debian, Run command service mysqld statuson Redhat. Then look at the output.

[email protected]:/home/avi# service mysql status/usr/bin/mysqladmin  ver  8.42 distrib 5.1.72, for debian-linux-gnu on i486copyright  (c)  2000,  2013, oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . Server version 5.1.72-2protocol version 10connection localhost via unix  socketunix socket /var/run/mysqld/mysqld.sockuptime: 1 hour 22 min 49  secThreads: 1  Questions: 112138  Slow queries: 1   Opens: 1485  flush tables: 1  open tables: 64  queries  per second avg:  22.567. 
2: How do I turn on or stop the MySQL service?

answer : Run the command service mysqld start services; Run the command service mysqld stop service.

[Email protected]:/home/avi# service mysql stopstopping MySQL database server:mysqld. [Email protected]:/home/avi# service mysql startstarting MySQL database server:mysqld. Checking for corrupt, not cleanly closed and upgrade needing tables.
Question 3: How do I log in to MySQL via the Shell?

answer : Run command mysql-u root-p

[Email protected]:/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), and Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of the Oracle Corporation and/or its affiliates. Other names trademarks of their respective owners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement. Mysql>
Question 4: How do I list all databases?

answer : Run the command show databases;

mysql> show databases; +--------------------+ | database            | +--------------------+ | information_schema |  | a1                  | | cloud               | | mysql              |  | phpmyadmin         | | playsms             | | sisso               | | test                | | ukolovnik           | | wordpress          | +-------------- ------+ 10 rows in set  (0.14 SEC)
Question 5: How do I switch to a database and work on it?

answer : Run command use database_name; Enter the database named 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>
Question 6: How do I list all the tables in a database?

answer : Run the command in the current database 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)
Question 7: How do I get the names and types of all Field objects in a table?

answer : Run command describe table_name;

mysql> describe oc_users; +-------- --+--------------+------+-----+---------+-------+ | field    | type          | Null | Key | Default |  extra | +----------+--------------+------+-----+---------+-------+ | uid       | varchar (  | NO   | PRI |   )       |       | | password |  varchar (255)  | NO   |     |          |       | +----------+--------------+--- ---+-----+---------+-------+ 2 rows in set  (0.00 sec) 
Question 8: How do I delete a table?

answer : Run command drop table table_name;

mysql> drop table lookup; Query OK, 0 rows Affected (0.00 sec)
Question 9: How do I delete a database?

answer : Run command drop database database-name;

mysql> drop DATABASE A1; Query OK, rows affected (0.07 sec)
Question 10: How can I view all the data in a table?

answer : Run command 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&nBsp;       | 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)
Question 11: How do I get all the data from a Field object (such as UID) from a table (such as Oc_users)?

answer : Run command select UID from oc_users;

Mysql> Select UID from oc_users; +-----+ | UID | +-----+ | Avi | +-----+ 1 row in Set (0.03 sec)
Question 12: Suppose you have a table named ' XYZ ', which has multiple fields, such as ' Create Time ' and ' engine '. The field named engine is made up of both ' memoty ' and ' MyIsam ' values. How to list only ' CreateTime ' and ' engine ' are the two columns and the engine value is ' MyIsam '?

answer : Run command 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)
Question 13: How do I list all data with the Name field value ' tecmint ' in table ' XRT ' and the web_address domain value ' tecmint.com '?

answer : Run command 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   |+---------------+---------------------+----------------+
Question 14: How do I list all the data in the table ' XRT ' where the Name field value is not ' tecmint ' and the web_address domain value is ' tecmint.com '?

answer : Run command 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 |+---------------+---------------------+----------------+
Question 15: How do I know the number of table insiders?

answer : Run command SELECT COUNT (*) from table_name;

Mysql> Select COUNT (*) from Tables; +----------+ | COUNT (*) |      +----------+ | 282 | +----------+ 1 row in Set (0.01 sec)

The above is the whole content of the article. Do you have any help with this 'Linux noodle question '? Don't forget to leave a message below and write down your valuable comments.

MySQL Basic question

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.