0% found this document useful (0 votes)
55 views

Introduction To Mysql: Database Management Systems

This document provides an introduction and overview for installing and using MySQL. It discusses installing MySQL on Linux, macOS, and Windows operating systems. It also provides a beginner's guide to connecting to a MySQL server, entering queries, creating and using databases and tables, loading and retrieving data. Key steps include adding MySQL repositories, running installation commands via package managers like APT and YUM, downloading native installation packages, and creating a root user password during the setup process.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Introduction To Mysql: Database Management Systems

This document provides an introduction and overview for installing and using MySQL. It discusses installing MySQL on Linux, macOS, and Windows operating systems. It also provides a beginner's guide to connecting to a MySQL server, entering queries, creating and using databases and tables, loading and retrieving data. Key steps include adding MySQL repositories, running installation commands via package managers like APT and YUM, downloading native installation packages, and creating a root user password during the setup process.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

INTRODUCTION TO MYSQL

Database Management Systems

Adam Thahir | Osman Hassan


Table of Contents

I. MySQL
II. Installing MySQL on Linux based systems
a. Installing MySQL using APT
b. Installing MySQL using YUM.
III. Installing MySQL on macOS
a. Installing MySQL using Native Packages
b. Installing and using the MySQL Preference Pace
IV. Installing MySQL on Microsoft Windows.
V. Beginners Guide.
a. Connecting to a MySQL Server
b. Entering Queries
c. Creating and using a Database
d. Creating a Table
e. Loading Data into a Table
f. Retrieving information form a table.
MySQL.
MySQL is a relational database management system. MySQL works on Microsoft Windows,
macOS, Linux and many other system platforms.

MySQL comes in two different editions, the MySQL Community Edition is free to use as well as
open-source. The MySQL Enterprise Edition is a subscription based service produced by Oracle
Corporation, this edition is targeted more towards the commercial market. Support for the
community edition can be found from the official documentation, support for the enterprise edition
can be obtained via Oracle’s official support

Installing MySQL on Linux Based Systems.


The steps to install Linux using a package manager would depend on the package manager used.
This guide would follow the steps using both APT and YUM.

Installing MySQL using APT.


One way to install MySQL on your Linux machine using APT is using the official package, for
this you would first need to add the MySQL APT repository. You can select and download the
DEB file from http://dev.mysql.com/downloads/repo/apt/ .

Once the package is downloaded, you would need to install the package, which can be done so by
the following steps on the Linux terminal:

sudo dpkg -i /PATH/version-specific-package-name.deb

During the installation you would be asked to choose the desired MySQL server version and other
components. The default options would be selected for you. Alternatively, if you wish to not install
any additional components, you can do so by selecting ‘none’ as your option.

Finally, you would need to update the package lists in your system for to recognize MySQL as a
new package. You can do so using the following command:

sudo apt-get update

Alternatively, you can also automatically install the MySQL server using the following command:

sudo apt-get install mysql-server


Additionally, assuming you now have the MySQL APT repository installed, you can also manually
install other products and components that are available from the MySQL APT repository. You
can install any the packages using the following commands:

sudo apt-get update

sudo apt-get install package-name

You can view the status of the MySQL server by running the following command:

sudo service mysql status

If you wish to stop the MySQL server, you can run the following command:

sudo service mysql stop

The following command would start the MySQL server:

sudo service mysql start

Installing MySQL using YUM.


To install MySQL on a Linux based system using the YUM, you would first need to add the
MySQL Yum repository into the system’s repository list (if it is not already added).

To add the MySQL Yum Repository, you would first need to download it from
http://dev.mysql.com/downloads/repo/yum/ . Once downloaded, you can use the following
command to install the downloaded package.

sudo yum localinstall platform-and-version-specific-package-name.rpm

If you would like to check if the Yum repository had been installed successfully, you can run the
following command:

yum repolist enabled | grep "mysql.*-community.*"

By default, there would already be a release series selected and you can proceed with the
installation. If you wish to do so, please refer to the steps available on the documentation from the
MySQL website.

Finally, you would need to install MySQL, the following command can be used to install MySQL:

sudo yum install mysql-community-server


In order to start the MySQL server, you can run the following command:

sudo service mysqld start

To view the status of the MySQL server, you can run the following command:

sudo service mysqld status

Installing MySQL on macOS


This guide will demonstrate how to install MySQL on macOS using Native packages.
Additionally, this guide would also cover how to install the MySQL Preference Pane

Installing MySQL using Native Packages


To install MySQL using Native Packages on macOS, you would first need to download the disk
image file which can be found on http://dev.mysql.com/downloads/mysql/ .

Once the file is downloaded, you would need to mount the disk image to see its contents, you can
mount the image by double clicking on the downloaded file.

Next, you would need to install the package, the package would be a pkg file named based on
downloaded version. You can double click the file to open the installer.

Once the installer is opened, the introduction screen would appear, click on “Continue” to begin
the installation.

Following the Introduction screen, you would see a copy of the relevant GNU General Public
License. Once reading though the License agreement, to continue, you would need to click on
‘Continue’ followed by ‘Agree’. You cannot go forward with the installation without agreeing to
the license.

To install MySQL with the default options, you can directly select ‘Install’ from the Installation
Type page that would appear. However, if you wish to alter certain components before installation,
you can do so by selecting ‘Customize’, you would have to click on ‘Install’ after finalizing the
components to install from the Customize menu.

After a successful installation, you would have to choose the default encryption type for password
that would be used in MySQL. Following this, you would also need to set up default root password.
Finally, you can choose to enable or disable MySQL on startup. Clicking on ‘Finish’ would
complete the installation process.

Installing and using the MySQL Preference Pane


The MySQL Preference pane enables you to start, stop and control automated startup during boot
of your MySQL installation. The Preference Pane would be included in the MySQL installation
package.

Preference pane should already be listed under your system’s System Preference window. As the
Preference Pane is installed with the same disk image file that installs the MySQL server.
However, if you had not installed the preference pane while installing the MySQL you can do so
using the same installer and selecting ‘Preference Pane’ from the customize menu in the installer.

Once installed, you can use the preference pane to control your MySQL server instance. You can
start, stop, recreate the data directory or uninstall the MySQL server from the Instances page. The
configuration page would show MySQL options such as the data directory and the path to the
configuration file.

The preference pane also shows the current setting for whether the MySQL server has been set to
start automatically.

Installing MySQL on Microsoft Windows


In the following section, you are going to see and learn how to download and install MySQL on
your windows 10 operating system. Please read and follow the following instructions. Let’s get
started:

First of all, try to download MySQL installer from https://dev.mysql.com/downloads/mysql/ and


execute it. Particularly, try to download the installer community version. Down in the same page
you may find a link like the one shown below, then by clicking and following the rest of the
instructions, you can able to download the MySQL installer community version.
Figure 1Choosing MySQL For Windows

Figure 2Downloading MySQL For Windows

After executing the setup file, you may end up having the window shown in Figure03. Then by
following the instructions, you can able to finish to the instalment of MYSQL on your windows.

Next, in the following section after license agreement, you will have different options of setup
types, as seen in Figure04. In this part, you can choose either Developer Default or Full, because
in these two you can get all the required MYSQL setups for this course.
Figure 3Terms of Service

Figure 4 Choosing a Setup Type


Figure 5 Checking Requirements

In the Check Requirements section, you may have some required products missing and in this case
you have to install it manually to your laptop. As shown in the figure below, Connector/Python is
missing but it is not necessary for me to download it, therefore I will leave it like that.

Figure 6 Installation
Next, as seen in Figure06 check if all the products are ready and then if yes click execute. If not
you have to resolve the ones shown not ready.

Figure 7Accounts and Roles

After completing the first part of the installation, in the second part especially in the third step, you
might need to create a password (Root Account Password). For this password you might use in
order to access your MYSQL.

After executing, you successfully installed MYSQL on your windows. You would need to start
your MySQL, open MySQL command line and it may require entering the password you have
created before.
Figure 8 Running MySQL on Windows

Beginner’s Guide
To view a list of all the options that can be used with the mysql command, you can run the
following:

mysql --help

Connecting to a MySQL Server


In order to connect to a MySQL server, you would need to provide a username. Additionally, if
the related user also has a password set, you would need to provide the password as well. To
connect to a MySQL server at localhost you can run the following command via terminal:

mysql -u user –p

If you are connecting to a MySQL server that is not on your machine, you would also need to
provide the hostname or address of the machine, you can run the following command via terminal
to do so.

mysql -h host -u user –p

If your server is set up such that it allows anonymous users to connect to the server, you do not
need to provide a username. However, if the server is not your local machine, you would still need
to provide a hostname or address.

If you would like to exit MySQL, you can do so simply by typing in “QUIT” or “\q”.
mysql> QUIT

(Notice that this is not within the bash terminal, and inside the MySQL application).

Entering Queries
Once connected to the MySQL server, you can start entering SQL queries. It is important to note
that connecting to the MySQL server does not mean that a database is selected.

SQL statements are typically followed by a colon. A good example statement is:

mysql> SELECT VERSION(), CURRENT_DATE;

This query would request the version number and the current date from the server. When a query
is entered, MySQL sends the query to the respective server in in order to execute the given query.
The result (if any) would be returned back to the screen. When the application is ready for another
input from the user, ‘mysql>’ would appear on the screen.

Keywords in the statements are case insensitive, which means that using “Select”, “SELECT”,
“sELECT” or any other permutation of the word would mean the same thing.

Creating and Using a Database.


Once connected to the Server, you are also able to create and use databases. Firstly, if you want to
know what databases already exist in the server, you can check the list of databases using the
following command from within the server:

mysql> SHOW DATABASES;

Using the command “Show Databases” would show you a list of databases that you have access
to. Which means that there may be other databases that exist in the server that you cannot see due
to you not having privileges (unless you are root).

If you would like to access a database that exists, you can do so by running the following
command:

mysql> USE dbName

The ‘USE’ statement is considered a special statement and requires it to be written on its own line.
Additionally, it also does not require a semi colon at the end of the statement.
If you are the administrator of the database, and wish to alter privileges that a specific user has on
a specific database, you can do so by running the following command:

mysql> GRANT ALL ON dbName.* TO 'userName'@'hostAddress';

If you are the administrator of the server, or if the administrator has granted you the right
privilege, you can also create your own database. This can be done by using the following
command:

mysql> CREATE DATABASE menagerie;

Creating a Table
Once connected to the Server and a database is chosen, you can use tables. To view a list of all the
tables, you can run the following command:

mysql> SHOW TABLES;

If you wish to create your own table, you can do so by running the following command:

mysql> CREATE TABLE tableName (var1 dataType, var2 dataType,


-> var3 dataType);

(datatype can be any data type, for example “varchar(20)”)

After creating a table, if you would like to verify that a the table was created, you can use the
‘Describe” statement.

mysql> DESCRIBE tableName;

Loading Data into A Table


Data can be loaded into a table in different ways. There is the ‘Insert’ statement in which you
would have to enter the data yourself, and then there’ the ‘Load Data’ statement, in which you are
able to load data from a file.

An Example use of the ‘Insert’ Function is as follows:

mysql> INSERT INTO tableName

-> VALUES ('value1','value2','value3');

An Example use of the ‘Load Data’ function is as follows:


mysql> LOAD DATA LOCAL INFILE '/path/file.txt' INTO TABLE tableName;

Retrieving Information from a Table


In order to retrieve information from a table, you can use the ‘Select’ statement. This statement
can be used with additional clauses such as the ‘Where’ clause to get more specific results.

An example ‘Select’ query:

SELECT * from tableName;

An example ‘Select’ query with additional ‘Where’ clause:

SELECT * from address WHERE variable1=value1;


You can also use retrieve information from more than one table at a time. Adding meaningful
additional clauses such as ‘JOIN’ or ‘INNER JOIN’ would allow you to display a joined view of
both tables.

Supposed you have two tables, table A and table B. Table A and B share a column, column X.
You can view a joined view of both tables by entering the following query:

SELECT * FROM A INNER JOIN B ON A.X = B.X;

Running this query would return a view which would show us values from both tables.

Example
This following section would demonstrate how you can use MySQL. The Examples would cover
a few parts from the “Beginner’s Guide” section. This example would show you how to Create a
database, select the database you created, create a table, view entries in a table and describe the
table, and finally, how to update an entry in a table.

In order to start MySQL, you need to type the full path name on Windows. If you’re using Linux
or Mac, you can simply type in “mysql” via the terminal.

To create a database and select it, you can follow the commands from the previous section, or look
into the commands used in Figure 9.

Once you have selected the database you created, you can proceed to type in other SQL commands,
such as the SQL command that is used to create a table. Figure 10 shows an example on creating
a table.
Figure 9 Create and Use Database

Figure 10 Create Table

Having a table created does not mean that there would be values entered into the table by default.
Figure 11 shows that the created table has no rows entered. Additionally, the ‘Describe’ feature is
also shown where you can see details of a selected table.
Figure 11 Select and Describe

You can insert entries into a selected table by following the steps showed in Figure 12. By default,
all columns are nullable unless specified otherwise, this means that if no entry has been specified
for a column when entering a new row, by default the column will be filled with a ‘NULL’ value.

Figure 12 Insert query and update Query


As seen from the ‘SELECT’ query in Figure 12, two columns remain to be NULL values. SQL
allows us to change any value of a column using it’s ‘UPDATE’ feature. Figure 12 demonstrates
how you can use the update feature. It is important to specify which row you want to update.

Finally, running the ‘SELECT’ query once again will show you the updated table with all the new
values.

Figure 13 Table after update Queries

You might also like