MySQL basic commands

Source: Internet
Author: User

Keyboard ESC clear Command \c Cancel command

Login mysql-ucountname-p enter cmd command invalid in operating system environment variable register MySQL

Show all databases show databases

Display table use dbname;show tables;

Display table structure desc tname;

Register MySQL account grant all on dbname.* to "countname" @ "localhost" identified by "PWD";

Create DATABASE dbName;

Delete database drop databases dbName;

Backing up the database Mysqldump-uroot-p dbname>d:/123.sql;

Import mysql-uroot-p dbname>d:/123.sql;

Use DbName; SOURCE D:/123.sql;

MySQL state information status;

CREATE TABLE Student

(Id int unsigned primary key auto_increment, primary key auto-increment

No Int (3) Zerofill insertion 3 loser 003

Sex,tinyint default 0)


Select if (Sex, "Boy", "schoolgirl") from student

Select Concat ("name": SName, "gender", sex) from student

SELECT * FROM Studnet limit 2 take the first two

Select Sname from student order by birthday LITMI 1, 1; Find the second-oldest student


ALTER TABLE student modify name character set UTF8;


Show character set;

Show collation; character Set validation rules

Show CREATE TABLE Student

The variables in MySQL do not have to be declared beforehand, use "@ variable name" when using it.


First usage: Set @num = 1; or set @num: = 1; To use variables to save the data, use the @num variable directly


Second usage: select @num: = 1; or select @num: = field name from table name where ...


Note the above two assignment symbols, which can be "=" or ": =" when using set, but must use ": = Assignment" When using Select


To set a global variable, there are two different ways:

Set global var_name = value; Note: Global cannot be omitted here. According to the manual, the set command sets the variable without specifying global, session, or local, using the session by default

SET @ @global. Var_name = value; Ditto


To see a global variable, there are two different ways:

SELECT @ @global. var_name;ame = value; Ditto


MySQL basic commands

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.