Installing MySql and creating a database

Lesson Details:
June 29, 2020


I: Introduction

A: Programming Languages are the most important part of Information Technology. It is very difficult to get a job in Information Technology field without any programming knowledge.

In Information Technology field, it is very difficult to get a good job without having good knowledge of programming languages. This is because, a programmer who knows a variety of programming languages can develop a large number of applications for a company. He will be able to do more work and reduce the time taken for development.

Programming languages are the language which is used by computer to understand the instructions given by user or programmer. The first programming language was developed in 1950s by John Backus. The first programming language was called FORTRAN.

The purpose of this article is to introduce different types of programming languages and how they are used in different fields of Information Technology.

II: Body

A: Installing mysql and creating a database

MySQL is one of the most widely used database management systems (DBMS). It is an open-source software which is written in C and C++ programming language. It is available in various versions which can be used on different platforms like Linux, Windows, UNIX etc. MySQL was developed in the year 1995 by Michael Widenius and David Axmark. The latest version of MySQL is 5.6 which comes with improved features. It has many improvements than previous versions. It has added new features like compression, UNION query, built-in functions, improved performance etc. MySQL also provides many APIs which makes it easier for developers to use it in their applications.

Installing MySQL

The installation process depends on the operating system you are using. For example, Windows users will need to visit the official website of MySQL and download the setup file according to your OS architecture i.e 32bit or 64bit. After downloading, install it by following the instructions displayed on your screen. The installation process should be easy for every user if he follows the instructions carefully. The installation process may vary slightly for different OS’s but the basic steps remain the same throughout.

Create a Database using SQL

After installing MySQL server, connect to it using SSH or any other tool available for your operating system. Open the terminal/command prompt and type “mysql -uroot -p”, where “-u” stands for user, “-p” stands for password and “-p” stands for prompt i.e the terminal/command prompt should ask you for your password. If you have done everything correctly, you should see something similar to this screenshot below:

Now, create a database by executing the following SQL statement:

CREATE DATABASE testdb; 1 CREATE DATABASE testdb ;

Above statement creates a database called “testdb” with no tables or privileges. You can create any database name you want after replacing it with “testdb” in above SQL statement. Now you can open your database from anywhere by typing mysql -u username -p testdb at the terminal prompt. Replace username with your mysql username and testdb with your database name. You should see your database opened with no tables or privileges as shown below:

Creating a table in a database using SQL

In order to create a table in your database from sql prompt, you need to execute SQL statements with proper syntax as shown below:

CREATE TABLE `mkyong`.( `subject` varchar(50) NOT NULL, `slug` varchar(50) NOT NULL, `description` text NOT NULL, PRIMARY KEY (`subject`,`slug`) ) TYPE=InnoDB DEFAULT CHARSET=latin1; 1 2 3 4 5 6 7 CREATE TABLE ` mkyong ` . ( ` subject ` varchar ( 50 ) NOT NULL , ` slug ` varchar ( 50 ) NOT NULL , ` description ` text NOT NULL , PRIMARY KEY ( ` subject ` , ` slug ` ) ) TYPE = InnoDB DEFAULT CHARSET = latin1 ;

We have created a table called mkyong with 4 columns – subject, slug, description and primary key – subject and slug – which we created by giving default values – subject as mkyong and slug as subject – and also told MySQL that table/database should be created as InnoDB type and default character set should be latin1. The SQL statement should be executed from our favourite command prompt or terminal window or any other tool that we use to access MySQL server from our operating system of choice – this could be PuTTY on windows or SSH on Linux etc.

Inserting data into a table using SQL

Now that we have created a new table called “mkyong” on our MySQL server we can insert some data into it by executing SQL statement as shown below:

INSERT INTO `mkyong`(`subject`,`slug`,`description`) VALUES('Programming', 'programming', 'programming'); 1 INSERT INTO ` mkyong ` ( ` subject ` , ` slug ` , ` description ` ) VALUES ( 'Programming' , 'programming' , 'programming' ) ;

Here we inserted one record into our table with three columns – subject as ‘Programming’ , slug as ‘programming’ , description as ‘programming’ . We have provided values for all three columns by placing them between double quotes after providing table name at the beginning of SQL statement. After inserting data into our table, we can check whether it has been inserted successfully or not by executing this statement:

SELECT * FROM mkyong; 1 SELECT * FROM mkyong ;

This will give you all records from our table called mkyong as shown below:



loader
Course content