Home Tutorials Training Consulting Products Books Company Donate Contact us









NOW Hiring

Quick links

Share

This tutorial explains how to install MySQL and how to create and query a database. This tutorial is using Ubuntu.

1. Overview

MySQL is a popular relational open source database. Applications can use this database to persist data.

This tutorial covers the installation of MySQL and the usage of the database.

2. Installation of MySQL

2.1. Ubuntu

Under Ubuntu you can install MySQL with the following command:

sudo apt-get install mysql-server

The installation procedure allow you to set the root password.

2.2. Windows

Under Windows download the community edition from http://dev.mysql.com/downloads/. For windows you have installer program available which guides you through the installation process.

2.3. Resetting the password

See Ubuntu password reset to learn how to set and reset your password under Ubuntu.

3. Connecting to MySQL

MySQL provides the mysql command line interface for administrative work. To connect to the MySQL database server use the following command:

# connect as root to MySQL server
mysql -u root -p

Once you have created a database on this server you can also connect directory to the database with the following command.

mysql db_name -u user -pmypassword

The default port of the database server is 3306. For example, the Java JDBC connection string to connect to the iotcloud database would be jdbc:mysql://localhost:3306/iotcloud.

4. Further SQL commands

Please see SQL Tutorial for the usage of SQL commands.

5. Import and export

The mysql command line interface allows you to export your database and import existing backups. The mysqldump command provides the option to create backup of your database, e.g. export your database.

To export the database use the following command.

# creates a dump of the database vogella_blog
mysqldump vogella_blog > vogella_blog.sql -p

To import an existing SQL dump file use the following command.

# vogella_blog.sql is your exported SQL file
# use option -p to enter your password
mysql vogella_blog < /var/www/vhosts/vogella.com/vogella_blog.sql -p

6. About this website

7.1. vogella GmbH training and consulting support

TRAINING SERVICE & SUPPORT

The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.

The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.

Copyright © 2012-2017 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.

See Licence.