Summary of MySQL operation under CMD

Source: Internet
Author: User
Tags import database

1. Link Database
C:\>mysql-hlocalhost-uroot-p//Press ENTER, you will be prompted for the password, if the password is empty direct enter
C:\>mysql--help
C:\>mysqladmin-uroot-p Password//Follow the prompts to change the password, the password is not filled out as the password is empty

2. Database operations (CREATE database school_db, create data table under it students)
Create Database school_db;
show databases;
Use database school_db;
Select Database ();
Show tables;
drop database;

3. Data Sheet operation
CREATE TABLE Students (
ID int unsigned NOT NULL Auto_increment primary key,
Name Char (8) is not NULL,
Sex char (4) NOT NULL,
Age tinyint unsigned is not NULL,
Tel char (+) NULL default "-"
);

INSERT into students values (NULL, ' Tom ', ' man ', 22, ' 13249076325 ');
INSERT into students (Name,sex) VALUES (' Lucy ', ' woman ');

SELECT * from students;
SELECT * from students where name is like "%l%";
SELECT * from students where id<5 and age>20;
SELECT * FROM students order by ID limit 0, 2;

Update students set Tel=default where id=5;
Update students set Name= "Jack", age=age+1 where id=1;

Delete from students;
Delete from students where id=2


4. Changes to the post-creation table:
ALTER TABLE students add address char (60);
ALTER TABLE students add birthday after age;

ALTER TABLE students Change Tel telphone char (+) Default "-";
ALTER TABLE students change name name char (+) not null;

ALTER TABLE students drop birthday;

ALTER TABLE students rename workmates;
ALTER TABLE students rename my_db.students; Move the table below the database my_db and name it students

drop table workmates;


Drop database school_db;


5. Export the Import database and data table
C:\>mysqldump-uroot school_db > E:\school_db.sql;
C:\>mysqldump-uroot school_db students > E:\school_db_students.sql;

C:\>mysql-uroot-d school_db < E:/school_db.sql; With the bottom source
C:\>mysqldump-uroot school_db < E:/school_db.sql; To import a database into a database
C:\>mysqldump-uroot school_db < E:/school_db_students.sql; Import a data table into a database
Mysql>use school_db;
Myslq>source E:/school_db.sql;

Summary of MySQL operation under CMD

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.