MySQL Database (i)

Source: Internet
Author: User
Tags mysql version


1. Operation Database
Creating a database: Create databases dbname;
Show all databases: show databases;
Use the MySQL command show create Database dbname;
You can view information about the database (such as MySQL version ID number, default character set, and so on).
Select default database: Use dbname;
Delete the database, use the SQL statement to drop dbname;


2, the operation of the database table structure:
You must first use the database before you create a database table.

CREATE TABLE Students (
ID int unsigned NOT NULL Auto_increment primary key,
Name varchar (8) is not NULL,
Sex char (4) NOT NULL,
Age Int. unsigned NOT NULL
); Engine=innodb DEFAULT Charset=utf8;

Use the MySQL command "desc students;" You can see the table structure with the table named TABLE_NAME.

Use the MySQL command "show create table students;" View detailed information named table_name table.

--Add columns
--ALTER TABLE name add column list data type [after insertion position];
ALTER TABLE students add birthday date after age;
--Add a column to the front
ALTER TABLE students add adress varchar (+) first;


--Modify Columns
--ALTER TABLE name change column Name column new name new data type
ALTER TABLE students change adress tel char (+) not null;
--If only the data type of the field is modified
--ALTER TABLE name modify field name new data type;


--Delete Columns
--ALTER TABLE table name drop column name;
ALTER TABLE students drop sex;


--Renaming a table
--ALTER TABLE name rename a new name;
ALTER TABLE students rename newstudents;


--Delete the entire table
--drop table name;
drop table newstudents;

--View Character Set
--View the currently supported MySQL character set
Show CharSet;

--Using the MySQL command
Show variables like ' character% ';
--You can view the character set used by the current MySQL service instance.

MySQL Database (i)

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.