Step By Step Create a MySQL Database Via Command Line on Windows.
Create a MySQL Database. This manual underneath will display you a way to Create a MySQL Database Via Command Line on Windows. It's clean to create a database, we have to know how to input SQL statements. By developing a database on your computer, you may be capable of collect, control, add, find the statistics saved for your laptop. Why we use MySQL in this academic to create a database. Because MySQL software is Open Source. And MySQL is the maximum popular Open Source SQL database control machine, is advanced, distributed, and supported through Oracle Corporation. Also, The MySQL Database Server could be very speedy, dependable, scalable, and smooth to use. MySQL Server works in customer/server or embedded systems. And many greater reasons why we use MySQL to create a database. Now, let we start our guide.
Database Programming.
- These commands under are intended for creating a MySQL database on a Windows operating gadget pc.
- Remember, each command ought to give up with a semicolon ( ;)
1. XAMPP
- Download and deploy Xampp server for your laptop.
- Now, open Xampp control panel.
- Then start MySQL.
|
XAMPP manage panel |
- Now, run Shell
2. Log In to the MySQL server.
- For the primary, we should log in to the MySQL server,
- To do this, we should enter a announcement to the command line with the subsequent command.
In this situation, we've special the user is
root with
u flag.if you have got detailed a password at your MySQL server, you should add
p flag at the quit of command line, instance.
which **** man or woman assign your password.at the other case you need to connect MySQL server to every other host, you must add
h flag on the quit of command line.if you efficiently log in to MySQL server, You must see MySQL set off that looks very much like this:
3. Create Database.
- To create a database with the call customers type the subsequent command:
- create database customers;
If your database is correctly created, you'll see the subsequent message at MySQL activate.
- Query OK, 1 row affected (0.00 sec)
If a database of the identical name already exists, then a brand new database will no longer be created and also you’ll get hold of this mistake:
- ERROR 1007 (HY000): Can't create database 'customers'; database exists
4. Show Databases.
- To view the database you’ve efficaciously created actually issue the following command:
The result will just like this.
|
show databases result |
5. Use Data Base.
- The use command is used when you have a couple of database on a MySQL server and want to replace between them. Statement : use [DatabaseName]; for example;
The result will just like this.
6. Create Table.
- At this sections will show you a way to create a table interior clients database.
- Now we can create a customers table. The desk incorporates information showed on the picture beneath.
|
table content - create MySQL table |
- Type the following command at MySQL prompt;
- create desk customers(customerNumber int(11), customerName varchar(50), smartphone varchar(50), addressLine1 varchar(50), city varchar(50), country varchar(50), postalCode varchar(15), united states of america varchar(50));
If the desk effectively created, the SQL activate must go back with this result.
- Query OK, 0 rows affected (0.28 sec)
Do the same steps to create some other desk.
7. Desc Table.
- DESC is short for DESCRIBE, this feature suggests the table structure.
- the announcement must see like this; ; desc desk name;
- Example ;
SQL activate should go back with this result.
- +------------------+-------------+------+-----+---------+-------+
- Field Type Null Key Default Extra
- +------------------+-------------+------+-----+---------+-------+
- customerNumber int(11) YES NULL
- customerName varchar(50) YES NULL
- smartphone varchar(50) YES NULL
- addressLine1 varchar(50) YES NULL
- city varchar(50) YES NULL
- state varchar(50) YES NULL
- postalCode varchar(15) YES NULL
- us of a varchar(50) YES NULL
- +------------------+-------------+------+-----+---------+-------+
- 8 rows in set (0.03 sec)
8. Alter Table.
- Alter desk used for alternate the table shape, there are many alternatives to apply adjust command.
- Now we will show add a primary key at the customers table.
- Now add a number one key at the customerNumber area.
- type the subsequent command at MySQL Prompt;
- alter desk clients upload number one key (customerNumber);
SQL activate should go back with this result.
- Query OK, 0 rows affected (0.63 sec)
- Records: 0 Duplicates: 0 Warnings: 0
Now, back to the desc table command.sql activate should go back with this result.
|
alter table - create a primary key |
You ought to see a
PRI under the key column.
9. Input Data Into Table.
- This sections will give an explanation for to you a way to input information to the desk.
- The statements ought to appear to be this;
- insert into table name (field1, field2, field3, ....fieldx) values (values1, values2, values3... Valuesx);
example.
- insert into customers (customerNumber, customerName, smartphone, addressLine1, metropolis, nation, postalCode, u . S . A .) values (1, 'Andy', '+62438999', 'royal avenue', 'kudus', 'crucial java', '59388', 'Indonesia');
SQL activate should go back with this result.
- Query OK, 1 row affected (0.04 sec)
Remember, to go into facts should correspond to the records type, as an instance.
- data type: Varchar = records must be enclosed in quotation marks.
- data kind: Int (numeric) = Data may be without delay written.
- data type : date = type with the following format (yyyy-mm-dd)
10. Show Table Data.
- How to expose records which is inserted into the desk.
- the statement is ;
example ;
SQL activate should go back with this result.
|
show table records - MySQL table |
How to expose precise desk datathe announcement is ;
- select field1, field2...filedx from table name;
example
- select customerName, metropolis, united states of america from customers;
SQL activate should go back with this result.
|
show certain table data |
Finish
Berikan Komentar
<i>KODE</i>
<em>KODE YANG LEBIH PANJANG</em>
Notify me
untuk mendapatkan notifikasi balasan komentar melalui Email.