MySQL


This draft deletes the entire topic.

expand all collapse all

Examples

  • 4

    Creating a database in MySQL

    CREATE DATABASE mydb;
    

    Return value:

    Query OK, 1 row affected (0.05 sec)


    Using the created database mydb

    USE mydb;
    

    Return value:

    Database Changed

    Creating a table in MySQL

    CREATE TABLE mytable
    (
      id              int unsigned NOT NULL auto_increment,
      username        varchar(100) NOT NULL,
      password        varchar(100) NOT NULL,
      PRIMARY KEY     (id)
    );
    

    CREATE TABLE mytable will create a new table called mytable.

    id int unsigned NOT NULL auto_increment creates the id column, this type of field will assign an unique numeric ID to each record in the table (meaning that no two rows can have the same id in this case), MySQL will automatically assign a new, unique value to the record's id field (starting with 1).

    Return value:

    Query OK, 0 rows affected (0.10 sec)


    Inserting a row into a MySQL table

    INSERT INTO mytable ( username, password )
    VALUES ( "myuser", "123456" );
    

    Example return value:

    Query OK, 1 row affected (0.06 sec)


    Selecting rows based on conditions in MySQL

    SELECT * FROM mytable WHERE username = "myuser";
    

    Return value:

    +----+----------+----------+
    | id | username | password |
    +----+----------+----------+
    |  1 | myuser   | 123456   |
    +----+----------+----------+
    

    3 rows in set (0.00 sec)


    Show tables in an existing database

    SHOW tables;
    

    Return value

    +----------------+
    | Tables_in_mydb |
    +----------------+
    | mytable        |
    +----------------+
    

    1 row in set (0.00 sec)


    Show list of existing databases

    SHOW databases;
    

    Return value:

    +-------------------+
    | Databases         |
    +-------------------+
    | information_schema|
    | mydb              |
    +-------------------+
    

    2 rows in set (0.00 sec)

    You can think of "information_schema" as a "master database" that provides access to database metadata.


Please consider making a request to improve this example.

Remarks

MySQL Logo

MySQL is an open-source Relational Database Management System (RDBMS) that is developed and supported by Oracle Corporation.

MySQL is supported on a large number of platforms, including Linux variants, OS X, and Windows. It also has APIs for a large number of languages, including C, C++, Java, .Net, Perl, PHP, Python, and Ruby.

Versions

VersionRelease Date
1.01995-05-23
3.191996-12-01
3.201997-01-01
3.211998-10-01
3.221999-10-01
3.232001-01-22
4.02003-03-01
4.12004-10-01
5.02005-10-01
5.12008-11-27
5.52010-11-01
5.62013-02-01
5.72015-10-01
Still have a question about Getting started with MySQL? Ask Question

Topic Outline