How to use the MySQL command line

Source: Internet
Author: User

Now we introduce MySQL command line, from the database to the table data deletion process, I hope to help users

method/Step

1. Log in to MySQL

CMD command terminal, if you have added the environment variables of MySQL, you can use the command directly

Mysql-uroot

Enter directly, then press the prompt for the password,

If you do not add a MySQL environment variable, you can switch to the bin directory under MySQL's installation directory, and then use

Mysq-uroot

You can also manually add environment variables for MySQL. There's no way to add an environment variable here.

Once the password is entered correctly, the Welcome to the MySQL monitor appears. Commands End With; The words "or \g ...",

The "mysql>" character prefix appears on the command line. Now you can use the command to manipulate MySQL. There has been no such experience, the original saw others in the command line inside the slam knock, on a pass of worship, think this person is very cow, now you can let not a pass worship.

All MySQL commands are ";" or \g as Terminator

2. Create a new database

After creating a new database, let's set up the charset first

mysql>SET NAMES UTF8;

And then create the database

mysql>CREATE DATABASE Lesson

3.

Show all databases

mysql>SHOW DATABASES;

 

4.

Working with databases

mysql> usedatabase name;

 

5.

New Table

mysql>CREATE TABLE Study (

ID int (one) unsigned not NULL auto_increment COMMENT ' student ID number ',

Username varchar (+) not NULL DEFAULT ' COMMENT ' student name ',

Class tinyint (3) unsigned not NULL,

Sex enum (' Male ', ' female ', ' confidential ') CHARACTER SET UTF8 COLLATE utf8_general_ci not NULL DEFAULT ' secrecy ' COMMENT ' sex ',

Addtime Int (Ten) not NULL DEFAULT ' 0 ',

PRIMARY KEY (ID)

) Engine=innodb COMMENT = ' student table ';

 

6.Show All Tables

mysql>SHOW TABLES;

 7.Modify the name of a table

mysql>RENAME TABLE Study to Study_new;

Or

mysql>ALTER TABLE study_new RENAME to study;

 8. Display field information

SHOW COLUMNS from study or DESCRIBE study

 9. Inserting data

mysql> INSERT INTO study (username,class,sex) VALUES (' Xiao Wang ', 1, ' Male '), (' Small Four ', 2, ' female ');

10. Querying data (making concat functions mosaic data)

Mysql> SELECT Username,concat (class, ' class '), sex from study;

 11. Delete Data

Mysql>DELETE from study WHERE id=1;

 12. Delete Data Sheet

DROP TABLE Study;

 13. Deleting a database

mysql> DROP DATABASE lesson;

How to use the MySQL command line

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.