Categories: misc

How to setup MySQL on local PC

In this post, we will learn how to setup MySQL on our local machines/system. This is one of the possible way to install, although you may prefer another approaches.


We will be installing both workbench and MySQL Server together using MySQL Community Server

Let’s begin.

Step 1: Download Community Server from here.

Current version is MySQL Community Server 5.6.25. It includes MySQL server, MySQL workbench and necessary connectors/plugins/tools.

Once download completed, Click on installer and follow default installation.

Below are the screenshots of installation process:

Step 2: Once the installation done, You can create a new Schema/database [look at upper toolbar on workbench for quick links]. In MySQL, a schema is synonymous with a database.

Click on highlighted link to create a schema, it will open a popup and guide you to create a Schema.

Alternatively, you can execute following SQL in SQL tab from above toolbar to create the database.
$>create DATABASE mydatabase;

Step 3: Once the schema created, it will be shown in Navigator pane on left. You may decide to set it as Default schema by select schema->Right click->Set As Default Schema.

Step 4: Grant necessary privileges so that your user can access the tables/other artifacts from that database. Execute following SQL inside an SQL tab.

$> GRANT ALL PRIVILEGES ON mydatabase.* TO “myuser”@”localhost” IDENTIFIED BY “mypassword”;

User, password mentioned here are the one your external application will use to connect to database. The quotes mentioned above are required.

Step 5: Now you can access your database from your external applications using following url:

URL : jdbc:mysql://localhost:3306/mydatabase
user/password : myuser/mypassword as defined in step 4. Port mentioned in URL is the default port used but you can change it using workbench.

That’s it. You may do everything we discussed above using mysql command line option instead of workbench.

In case you are interested to see MySQL in action, Post Spring 4 MVC + Hibernate4 + MySQL + Maven integration example using annotations contains a real-world example of a Spring MVC based web application, connecting to MySQL using Hibernate.

References

View Comments

  • When i was trying to grant privileges by copying query from step 4 i get syntax error, this one is correct :
    GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

Share
Published by

Recent Posts

Spring Boot + AngularJS + Spring Data + JPA CRUD App Example

In this post we will be developing a full-blown CRUD application using Spring Boot, AngularJS, Spring Data, JPA/Hibernate and MySQL,…

7 years ago

Spring Boot Rest API Example

Spring Boot complements Spring REST support by providing default dependencies/converters out of the box. Writing RESTful services in Spring Boot…

7 years ago

Spring Boot WAR deployment example

Being able to start the application as standalone jar is great, but sometimes it might not be possible to run…

7 years ago

Spring Boot Introduction + hello world example

Spring framework has taken the software development industry by storm. Dependency Injection, rock solid MVC framework, Transaction management, messaging support,…

7 years ago

Secure Spring REST API using OAuth2

Let's secure our Spring REST API using OAuth2 this time, a simple guide showing what is required to secure a…

8 years ago

AngularJS+Spring Security using Basic Authentication

This post shows how an AngularJS application can consume a REST API which is secured with Basic authentication using Spring…

8 years ago