Create a table in Mysql

Source: Internet
Author: User

Learning Mysql databases, Mysql table creation is the most basic knowledge. The following is an example of creating a Mysql table for your reference. I hope it will help you learn how to create a Mysql table.

<! -- Create a Mysql table named world
Create three columns:
Id, which is a number.
Name, type is character
Location, which is a character

 
 
  1. <? Php
  2. ///// // Create a connection with mysql
  3. $ Con = mysql_connect ("localhost", "root ","");
  4. If (! $ Con)
  5. {
  6. Die ('could not connect: '. mysql_error ());
  7. }
  8. //// // Create a database
  9. If (mysql_query ("create database my_db", $ con ))
  10. {
  11. Echo "Database created ";
  12. }
  13. Else
  14. {
  15. Echo "Error creating database:". mysql_error ();
  16. }
  17. Mysql_select_db ("my_db", $ con); // select a database
  18. ////////// Table creation statement
  19. $ SQL = "CREATE TABLE world
  20. (
  21. Id int (20 ),
  22. Name varchar (6 ),
  23. Location varchar (15)
  24.  
  25. )";
  26. Mysql_query ($ SQL, $ con); // execute the table creation statement
  27. //// // Insert data into the table
  28. Mysql_query ("insert into world (Id, Name, Location)
  29. VALUES ('20140901', 'ning', '1970. 100000 ')");
  30. // Close the connection
  31. Mysql_close ($ con);?>

Then add some records to it -->

MySQL connection query Overview

MySQL queries tables with matching letters

MySQL table lock status and number of opened files

View the processes of the MySQL server

How to enable MySQL slow Query

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.