Results 1 to 2 of 2

Thread: How to Create a MySQL Database on Linux

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    76,596

    Default How to Create a MySQL Database on Linux

    First you can login as root on your mysql server using:

    Code:
    mysql -u root -p
    If a password is required,

    Code:
    $ mysql -u root -p
    Enter password:
    You should now be at a MySQL prompt that looks very similar to this:

    Code:
    mysql>
    We can now create a database by run command:

    Code:
    CREATE DATABASE tutorial_database;

    Code:
    Query OK, 1 row affected (0.00 sec)
    The database name we have chosen already exists, run command:

    Code:
    CREATE DATABASE IF NOT EXISTS tutorial_database;

    Code:
    Query OK, 1 row affected, 1 warning (0.01 sec)

    If we leave the "IF NOT EXISTS" option off, and the database already exists, we will receive the following error:

    Code:
    ERROR 1007 (HY000): Can't create database 'tutorial_database'; database exists

    To view a list of the current databases, use run command:

    Code:
    SHOW DATABASES;

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    To see all tables in a database, run

    Code:
    user DB_NAME;
    show tables;
    Commands you run inside MySQL command prompt are called SQL (Structured Query Language) statements. All SQL statements ends with semicolon (;)


    Code:
    [email protected]:~ $ mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> use vshare
    sReading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +------------------------+
    | Tables_in_vshare       |
    +------------------------+
    | admin_log              |
    | adv                    |
    | buddy_list             |
    | channels               |
    | comments               |
    | config                 |
    | contact                |
    | disallow               |
    | email_templates        |
    | favourite              |
    | feature_requests       |
    | friends                |
    | group_members          |
    | group_topic_posts      |
    | group_topics           |
    | group_videos           |
    | groups                 |
    | guest_info             |
    | import_auto            |
    | import_track           |
    | inappropriate_requests |
    | mail_logs              |
    | mails                  |
    | packages               |
    | pages                  |
    | playlists              |
    | playlists_videos       |
    | poll_question          |
    | poll_results           |
    | process_queue          |
    | profile_comments       |
    | relation               |
    | sconfig                |
    | servers                |
    | sitemap                |
    | subscriber             |
    | tag_video              |
    | tag_video_backup       |
    | tags                   |
    | tags_backup            |
    | user_logins            |
    | users                  |
    | uservote               |
    | verify_code            |
    | video_responses        |
    | videos                 |
    | view_log               |
    | words                  |
    +------------------------+
    48 rows in set (0.00 sec)
    
    mysql>
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •