Introduction To Mysql: Database Management Systems
Introduction To Mysql: Database Management Systems
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
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:
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:
Alternatively, you can also automatically install the MySQL server using the following command:
You can view the status of the MySQL server by running the following command:
If you wish to stop the MySQL server, you can run the following command:
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.
If you would like to check if the Yum repository had been installed successfully, you can run the
following command:
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:
To view the status of the MySQL server, you can run the following command:
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.
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.
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
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.
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
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.
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:
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.
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:
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:
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:
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:
If you wish to create your own table, you can do so by running the following command:
After creating a table, if you would like to verify that a the table was created, you can use the
‘Describe” statement.
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:
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
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.
Finally, running the ‘SELECT’ query once again will show you the updated table with all the new
values.