Description of the correct MySQL database operation process

Source: Internet
Author: User

The following articles mainly introduce the correct procedures for MySQL database operations, as well as descriptions of some things worth attention during the installation process. At the same time, I would like to give you some advice, in the actual installation process, you must remember your password, which is the key to log on to MySQL in the future.

MySQLDatabase Operation 1. log on to the MySQL database server

To log on to MySQL, you need to switch to the bin directory of MySQL under dos and perform the following operations:

Syntax format:

 
 
  1. MySQL-h host_name-u user_name-p password-the local host-h and host_name can be saved)

My Experience:

C: \ program files \ MySQL server 4.1 \ bin> MySQL-u root-p

Enter password :******

First Enter the user name and password login requirements plus-p), press Enter, and then "Enter password:" appears, then Enter the password and press Enter, so that you can

Log on to MySQL. Otherwise, the logon fails.

After successful login, the following information is displayed:

 
 
  1. Welcome to the MySQL monitor. Commands end with ; or \g.  
  2. Your MySQL connection id is 1 to server version: 4.1.10-nt  
  3. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  4. MySQL> 

Mark "MySQL>". When you see the top cell on the far left of the window, you can enter the command to perform the operation.

MySQL> \ s view version information

MySQL> \ q or MySQL> quit

MySQL> \ h or MySQL> help to view commands related to other database servers)

MySQLDatabase Operations 2. Database Operations

Note that the displayed results of all examples are the results of the following steps in order.

2.1 query statement

2.1.1 view the MySQL database version number and the current server date

 
 
  1. MySQL> select version (), current_date; Operation Method 1)
  2. MySQL> select version ()
  3. ->, Current_date; Operation Method 2)

※Operation statements are separated by commas (,) and separated by commas (;). The operation ends. line breaks do not affect the operation process.

2.1.2 view all databases on the server

 
 
  1. MySQL> show databases; 

2.2 create a database

2.2.1 creating a database, of course, the database name "asb" cannot already exist)

 
 
  1. MySQL> create database asb; 

2.2.2 select a database to make it the database for the current operation

 
 
  1. MySQL> use asb; 

After the selection is successful, the following information is displayed:

 
 
  1. Database changed 

You can even directly select the database to be operated when logging on to the MySQL database using window commands, provided that the asb database exists)

 
 
  1. bin>MySQL asb -u uesername -p  
  2. Enter password:****** 

2.2.3 view the name of the database currently operated

 
 
  1. MySQL> select database(); 

The result is as follows:

 
 
  1. +------------+  
  2. | database() |  
  3. +------------+  
  4. | asb |  
  5. +------------+  
  6. 1 row in set (0.00 sec) 

2.3 create a table

2.3.1 "create table" is used to create a table in the current database. If not, use 'use' to select the database for which the table is to be created)

 
 
  1. MySQL> create table emp(emp_id varchar(6)  
  2. -> ,emp_name varchar(10)  
  3. -> ,emp_age int  
  4. -> ,emp-sal int  
  5. -> ,emp_bir date  
  6. -> ,emp_sex varchar(5)  
  7. -> ); 

2.3.2 check the tables in the current database to check whether the "emp" table in the previous example is successfully created)

 
 
  1. MySQL> show tables; 

If it is successful, it will be shown as follows:

 
 
  1. +---------------+  
  2. | Tables_in_asb |  
  3. +---------------+  
  4. | emp |  
  5. +---------------+  
  6. 1 row in set (0.00 sec) 

2.3.3 view the structure of a data table

 
 
  1. MySQL> describe emp; 

The running result is shown as follows:

 
 
  1. +----------+-------------+------+-----+---------+-------+  
  2. | Field | Type | Null | Key | Default | Extra |  
  3. +----------+-------------+------+-----+---------+-------+  
  4. | emp_id | varchar(6) | YES | | NULL | |  
  5. | emp_name | varchar(10) | YES | | NULL | |  
  6. | emp_age | int(11) | YES | | NULL | |  
  7. | emp_sal | int(11) | YES | | NULL | |  
  8. | emp_bir | date | YES | | NULL | |  
  9. | emp_sex | varchar(5) | YES | | NULL | |  
  10. +----------+-------------+------+-----+---------+-------+ 

The above content is an introduction to MySQL database operations. I hope you will have some gains.

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.