Basic knowledge of MySQL database

Source: Internet
Author: User
Tags toad for mysql

The following articles mainly introduce the basic knowledge of the MySQL database, including the creation of the MySQL database and the description of some related data types, which also involves the creation of tables, the following is a detailed description of the article. I hope you will find some gains.

MySQL database installation is best to change the character set UTF8

Create a database

 
 
  1. create database mydata;  
  2. use mydata; 

Data Type int double char varchar datetime longtext

Create table dept

 
 
  1. (  
  2. deptno int primary key,  
  3. dname varchar(14),  
  4. loc varchar(13)  
  5. );  
  6. create table emp  
  7. (  
  8. empno int primary key,  
  9. ename varchar(10),  
  10. job varchar(15),  
  11. mgr int,  
  12. hiredate datetime,  
  13. sal double,  
  14. deptno int,  
  15. foreign key (deptno) references dept(deptno)  
  16. );  

MySQL database execution script file. SQL \. file path or source file path

?

SQL file -- Comment

MySQL administrator, toad for MySQL

View database show databases;

View the table show tables;

View the table structure desc dept;

Insert data

 
 
  1. intsert into dept values(1,'a','a');  
  2. commit; 

Select * from dept order by deptno desc limit 3, 2; count two after the third one)

Auto-increment create table article

 
 
  1. (  
  2. id int primary key auto_increment,  
  3. title vachar(255)  
  4. );  
  5. insert into article values(null,'a');  
  6. insert into article(title) values('c'); 

Date Processing

Obtain the current date select now ();

Convert string select date_format (now (), '% Y-% m-% d % H: % I: % s ');

 
 
  1. Jdbc connection to MySQL
  2. Connection conn = null;
  3. Statement stmt = null;
  4. ResultSet rs = null;
  5. Try {
  6. Class. forName ("com. MySQL. jdbc. Driver"). newInstance ();
  7. Conn = DriverManager. getConnection ("jdbc: MySQL: // localhost/test? User = root & password = root ");
  8. Stmt = conn. createStatement ();
  9. Rs = stamt.exe cuteQuery (SQL );
  10. }
  11. Catch (Exception e ){}
  12. Finally {
  13. Try {
  14. If (rs! = Null) {rs. close; rs = null ;}
  15. If (stat! = Null) {stat. close; stat = null ;}
  16. If (conn! = Null) {conn. close; conn = null ;}
  17. }
  18. Catch (SQLException e ){
  19. E. printStackTrace ();
  20. }
  21. }

The above content is an introduction to the MySQL database knowledge. I hope you can gain some benefits.

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.