Create Database and tables in MySQL

Ads
 

Create Database and tables in MySQL

Hi,

How to create database and tables in MySQL Database? Explain me step-by-step as I am beginner in MySQL.

Thanks

View Answers

June 26, 2016 at 12:28 AM

Hi,

First of all you have to connect to MySQL database through command line tool.

Connecting to MySQL Database:

mysql -uroot -p

Here in -uroot, root is the username of database. Replace this with your database user name for example if your username is 'abc' then the command will be:

mysql -uabc -p

Press enter on the command prompt/terminal and mysql command line tool will ask for the password. Enter the password and if password is correct mysql prompt will open.

[email protected]:~$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.12-0ubuntu1.1 (Ubuntu)

Copyright (c) 2000, 2016, 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>

Now to create database use following command:

mysql> CREATE DATABASE tutorial;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| tutorial           |
+--------------------+
5 rows in set (0.00 sec)

The show databases; command displays the names of the databases.

Now you have to connect to database, type following command:

mysql> connect tutorial;
Connection id:    6
Current database: tutorial

Here is the sql to create table:

mysql> CREATE TABLE email
    -> (
    -> first_name varchar(20),
    -> last_name varchar(20),
    -> email varchar(40),
    -> email_count Int
    -> )
    -> ;
Query OK, 0 rows affected (0.02 sec)

Following command displays the newly created table:

mysql> show tables;
+--------------------+
| Tables_in_tutorial |
+--------------------+
| email              |
+--------------------+
1 row in set (0.00 sec)

mysql>

Check more tutorials at Create a database.

Check 100s of tutorials of SQL at SQL Tutorials with MySQL Database.

Thanks

Ads









Related Tutorials/Questions & Answers:
Create Database and tables in MySQL
Create Database and tables in MySQL  Hi, How to create database and tables in MySQL Database? Explain me step-by-step as I am beginner in MySQL. Thanks   Hi, First of all you have to connect to MySQL database through
MySQL Create Database
MySQL Create Database        ... to create the database on MySQL Server. MySQL Database server is one of the very... database <database name> is used to create a new database on the MySQL
Advertisements
Create xsd files from database tables
Create xsd files from database tables  Hi, I work on a Java JEE... database tables.... At the moment we write the xsd files representing a database table structure by hand
Video Tutorial: How to create a database in MySQL using Command prompt?
How to create a database in MySQL using Command prompt MySQL is an Operation... is the video tutorial of "How to create database in MySQL using command prompt?": In this tutorial we will learn how to create a database in MySQL using
Mysql List Tables
Mysql List Tables     ... of tables in database name 'Table_in_girish'. The Syntax used to display the list of tables in database are given below: show tables :The showtables is used
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
Setup MySQL Database
/mysql/mysql5/Installing-MySQL-on-Windows.shtml Creating Database : You can create mysql database...Setup MySQL Database          In this section we will create database and table
program to create nested tables
program to create nested tables  program to create nested tables
Different tables present in MySQL
; Hi friends, Total 5 types of tables we can create 1. MyISAM 2. Heap 3... When you fire the above create query MySQL will create a MyISAM table. Thanks...Different tables present in MySQL  What are the different tables
Mysql List Tables
Mysql List Tables      ... of tables in database name 'Table_in_girish'. The Syntax used to display the list of tables in database are given below: show tables: The showtables is used to show
Create Table in Database
are using MySQL command query to create a table in database name countryinfo... Create Table in Database   ... Tables. The Tables contain the information on data for the database. Each Table
MySQL Create Table
MySQL Create Table       Here, you will read the brief description about the MySQL create table. The CREATE TABLE statement is used for creating a table in database
Creating Database Tables and Indexes
Creating Database Tables and Indexes   ... the allowable syntax for identifiers in MySQL. The identifiers are Database, table, index...; Database 64 table 64 column 64 Index 
mysql select from multiple tables
mysql select from multiple tables   how can i select the date field from multiple tables in mysql?   "UNION" can be used to select data from multiple tables in my sql... for example (SELECT * from name where `name
Purge Data from Mysql tables
Purge Data from Mysql tables  Hi, i have to write a mysql procedure to purge data from tables. but written procedure clear entire tables data. Please give me the solution for purging data. CREATE DEFINER=`root`@`localhost
update mysql database
update mysql database  update mysql database
create the SQL tables from an XML schema
create the SQL tables from an XML schema  I'm using Eclipse, Please let me know if anyone developped an application that would automatically create the SQL tables from an XML schema
Mysql Join 3 Tables
Mysql Join 3 Tables       Mysql Join 3 Tables is used to join 3 Tables using left join... an example from 'Mysql Join 3 Tables' using Left Join. To grasp this example
Create Database SQLite
Create Database SQLite  Hi, I am unable to create database in sqlite... it on Desktop and i add the table into my project. Create Table into MSQLite Database... of all open the MSQLite database and from top menu item's choose File->New
how to do two database tables in one page?
how to do two database tables in one page?  dear all: i want to show these two database tables in one page. one table on the left (dbtable.jsp... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); Statement st
DataBase Connectivity with MySql in Visual Web JSF Application Using Net Beans IDE
. In this application, we are going to create a database connection with mysql step...DataBase Connectivity with MySql in Visual Web JSF Application Using Net Beans...;  This Application illustrates how to create database
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
How do you map Java Objects with Database tables?
How do you map Java Objects with Database tables?  Hi, How do you map Java Objects with Database tables? thanks
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
JDBC : Create Database Example
JDBC : Create Database Example In this section you will learn how to create database using JDBC with example. Create Database : Database is an organized... the data.In Our discussion we are using MYSQL database. It is Relational DBMS so
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code...("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver
Mysql Create Table
Mysql Create Table       Mysql Create Table is used to create a table in database. Understand with Example The section of Tutorial will help you to create a table in database

Ads