Step By Step Create a MySQL Database Via Command Line on Windows.
Create a MySQL Database. This conduct below volition exhibit you lot how to Create a MySQL Database Via Command Line on Windows. It's slow to practise a database, nosotros must know how to larn into SQL statements. By creating a database on your computer, you lot volition endure able to collect, manage, add, honor the information stored on your computer. Why nosotros usage MySQL on this tutorial to practise a database. Because MySQL software is Open Source. And MySQL is the close pop Open Source SQL database administration system, is developed, distributed, in addition to supported past times Oracle Corporation. Also, The MySQL Database Server is real fast, reliable, scalable, in addition to slow to use. MySQL Server plant inwards client/server or embedded systems. And many to a greater extent than reasons why nosotros usage MySQL to practise a database. Now, allow nosotros start our guide.
Database Programming.
- These instructions below are intended for creating a MySQL database on a Windows operating organisation computer.
- Remember, each command must goal amongst a semicolon ( ;)
1. XAMPP
- Download in addition to install Xampp server on your computer.
- Now, opened upwardly Xampp command panel.
- Then start MySQL.
|
XAMPP command panel |
- Now, run Shell
2. Log In to the MySQL server.
- For the first, nosotros must log inwards to the MySQL server,
- To practise this, nosotros must larn into a disceptation to the command business amongst the next command.
- In this case, nosotros have specified the user is root with u flag.
- If you lot convey specified a password at your MySQL server, you lot must add together p flag at the goal of command line, example.
- which **** graphic symbol assign your password.
- At the other instance you lot desire to connect MySQL server to to a greater extent than or less other host, you lot must add together h flag at the goal of command line.
- If you lot successfully log inwards to MySQL server, You should run across MySQL prompt that looks real similar to this:
3. Create Database.
- To practise a database amongst the get upwardly customers type the next command:
- create database customers;
- If your database is successfully created, you lot volition run across the next message at MySQL prompt.
- Query OK, 1 row affected (0.00 sec)
- If a database of the same get upwardly already exists, thus a novel database volition non endure created in addition to you’ll have this error:
- ERROR 1007 (HY000): Can't practise database 'customers'; database exists
4. Show Databases.
- To sentiment the database you’ve successfully created only number the next command:
- The effect volition similar to this.
|
show databases result |
5. Use Data Base.
- The use command is used when you lot convey to a greater extent than than ane database on a MySQL server in addition to ask to switch betwixt them. Statement : use [DatabaseName]; for example;
- The effect volition similar to this.
6. Create Table.
- At this sections volition exhibit you lot how to practise a tabular array within customers database.
- Now nosotros volition practise a customers table. the tabular array contains information showed on the icon below.
|
table content - practise MySQL table |
- Type the next command at MySQL prompt;
- create tabular array customers (customerNumber int(11), customerName varchar(50), band varchar(50), addressLine1 varchar(50), urban total varchar(50), province varchar(50), postalCode varchar(15), Earth varchar(50));
- If the tabular array successfully created, the SQL prompt should supply amongst this result.
- Query OK, 0 rows affected (0.28 sec)
- Do the same steps to practise to a greater extent than or less other table.
7. Desc Table.
- DESC is brusque for DESCRIBE, this purpose shows the tabular array structure.
- the disceptation should run across similar this; ; desc tabular array name;
- Example ;
- SQL prompt should supply amongst this result.
- +------------------+-------------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +------------------+-------------+------+-----+---------+-------+
- | customerNumber | int(11) | YES | | NULL | |
- | customerName | varchar(50) | YES | | NULL | |
- | band | varchar(50) | YES | | NULL | |
- | addressLine1 | varchar(50) | YES | | NULL | |
- | urban total | varchar(50) | YES | | NULL | |
- | province | varchar(50) | YES | | NULL | |
- | postalCode | varchar(15) | YES | | NULL | |
- | Earth | varchar(50) | YES | | NULL | |
- +------------------+-------------+------+-----+---------+-------+
- 8 rows inwards laid (0.03 sec)
8. Alter Table.
- Alter tabular array used for change the tabular array structure, at that topographic point are many options to usage alter command.
- Now nosotros volition exhibit add together a psyche key at the customers table.
- Now add together a psyche key at the customerNumber field.
- type the next command at MySQL Prompt;
- alter tabular array customers add together psyche key (customerNumber);
- SQL prompt should supply amongst this result.
- Query OK, 0 rows affected (0.63 sec)
- Records: 0 Duplicates: 0 Warnings: 0
- Now, dorsum to the desc tabular array command.
- SQL prompt should supply amongst this result.
|
alter tabular array - practise a psyche key |
- You should run across a PRI under the key column.
9. Input Data Into Table.
- This sections volition explicate to you lot how to input information to the table.
- The statements should hold off similar this;
- insert into table get upwardly (field1, field2, field3, ....fieldx) values (values1, values2, values3... valuesx);
- example.
- insert into customers (customerNumber, customerName, phone, addressLine1, city, state, postalCode, country) values (1, 'Andy', '+62438999', 'royal street', 'kudus', 'central java', '59388', 'Indonesia');
- SQL prompt should supply amongst this result.
- Query OK, 1 row affected (0.04 sec)
- Remember, to larn into information must gibe to the information type, for example.
- data type: Varchar = data must endure enclosed inwards quotation marks.
- data type: Int (numeric) = Data tin endure straight written.
- data type : appointment = type amongst the next format (yyyy-mm-dd)
10. Show Table Data.
- How to exhibit data which is inserted into the table.
- the disceptation is ;
- example ;
- SQL prompt should supply amongst this result.
|
show tabular array information - MySQL table |
- How to exhibit specified tabular array data
- the disceptation is ;
- select field1, field2...filedx from table name;
- example
- select customerName, city, Earth from customers;
- SQL prompt should supply amongst this result.
|
show specified tabular array data |
- Finish
Add your comment