How to create databases in MySQL

Author: Randy Alexander
Date Of Creation: 1 April 2021
Update Date: 26 June 2024
Anonim
How to Create a MySQL Database for Beginners in MySQL Workbench
Video: How to Create a MySQL Database for Beginners in MySQL Workbench

Content

MySQL can be very intimidating. Every command must go through a command line interpreter (command prompt) completely without an intuitive interface. Therefore, equipping the basics of how to create and manipulate a database can save you a lot of time and hassle. Follow the instructions below to create a database of states in the US.

Steps

Method 1 of 2: Create and manipulate a database


  1. Query your new database. Now, once the base database has been set up, you can enter queries to obtain specific results. First, enter the command: SELECT * FROM the_bang ;. This command will return the entire database, as shown by the command " *" - meaning "all".
    • For more advanced queries, enter the following command: SELECT State, Population FROM COUNTRIES ORDER BY NUMBER ;. This command will return a datasheet with states sorted by population field value instead of alphabetical order. School The code will not be displayed by you just retrieving the data state and population.
    • To list the states by population in reverse order, enter the following command: SELECT state, population FROM state ORDER BY population DESC ;. Comeinand DESC lists them as descending value, from high to low instead of low to high.
    advertisement

Method 2 of 2: Learn more about MySQL


  1. Install MySQL on your Windows computer. Learn how to install MySQL on your home computer.
  2. Delete MySQL database. If you need to remove some of the outdated databases, follow this guide.

  3. Learn PHP and MySQL. Learning PHP and MySQL will help you create powerful websites for fun and for work as well.
  4. Backup your MySQL database. Data backup is always a must, especially for important databases.
  5. Change the database structure. If the needs for a database have changed, you may have to adjust its structure to handle other information. advertisement

Advice

  • Several commonly used data types (for a complete list see the mysql documentation at http://dev.mysql.com/doc/):
    • CHAR(length) - string of characters of predetermined length.
    • VARCHAR(length) - string of maximum length is length.
    • TEXT Character string up to 64KB of text.
    • INT(length) - 32-bit integer with the maximum number of digits length (with negative numbers, "-" is counted as a 'number').
    • DECIMAL(length,decimal) - The maximum number of characters displayed is length. Part decimal Specifies the maximum number of digits after the comma.
    • DATE - Value of day (year, month, day).
    • TIME - Value of time (hours, minutes, seconds).
    • ENUM(’value 1’,’value 2", ....) - List of counting values.
  • Some parameters are optional:
    • NOT NULL - A value must be provided. This field cannot be left blank.
    • DEFAULTdefault value - If no value is given, default value will be applied to this school.
    • UNSIGNED For numeric data, make sure that the value is never negative.
    • AUTO_INCREMENT Values ​​are automatically added each time a new row is added to the data table.