<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Archives - Codersee blog- Kotlin on the backend</title>
	<atom:link href="https://blog.codersee.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Kotlin &#38; Backend Tutorials - Learn Through Practice.</description>
	<lastBuildDate>Wed, 16 Apr 2025 04:50:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://blog.codersee.com/wp-content/uploads/2025/04/cropped-codersee_logo_circle_2-32x32.png</url>
	<title>MySQL Archives - Codersee blog- Kotlin on the backend</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MySQL Essentials: A Fast-Paced Introduction</title>
		<link>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/</link>
					<comments>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 27 Dec 2022 08:15:06 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504127</guid>

					<description><![CDATA[<p>Learn the essentials of MySQL in this fast-paced introduction. Get started with its genesis, advantages, drawbacks, and best use cases.</p>
<p>The post <a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Are you ready to dive into the world of <strong>MySQL</strong>? Whether you&#8217;re a beginner looking to get started with this powerful open-source database, or an experienced developer looking to brush up on your skills, this MySQL introduction has something for everyone.</p>
<p>In this fast-paced intro, <strong>you&#8217;ll learn the essentials of MySQL</strong>, including its:</p>
<ul>
<li>history</li>
<li>advantages</li>
<li>disadvantages</li>
<li>use-cases</li>
<li>and companies, which successfully use it to ship their products.</li>
</ul>
<p>And one more thing before we start. This article is a continuation of a series describing the <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">Top 8 Most Popular Databases</a>. If you would like to learn more about other solutions, then I highly recommend you bookmark that article and come back to it later.</p>
<h2>Explainer Animation</h2>
<p>If you enjoy <strong>whiteboard animations</strong>, then right here you can find a video version for this article:</p>
<p>&nbsp;</p>
<div style="text-align: center; width: 80%; margin-left: 10%;">
<a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FBMbJwvMLcnI%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<p>&nbsp;</p>
<p>If you find this content useful,<strong> please leave a subscription </strong> 😉</p>
<h2>MySQL Genesis</h2>
<p>So as the first thing in our introduction, let&#8217;s take a while to learn more about MySQL&#8217;s history.</p>
<p>MySQL was developed by a Swedish company called MySQL AB, which was founded in <strong>1995</strong> by Allan Larsson, David Axmark, and Michael Widenius. The name is a combination of Michael&#8217;s daughter&#8217;s name- <strong>My</strong>&#8211; and the abbreviation for <strong>S</strong>tructured <strong>Q</strong>uery <strong>L</strong>anguage (SQL).</p>
<p>The development began in <strong>1994</strong>, and the goal was to create a fast, reliable, and easy-to-use database system that could be used in a variety of applications. And although there were already a number of other database management systems available, many of these systems were complex to install and use, and they often required specialized skills and expertise to manage effectively. On the other hand, available open-source solutions were not as widely used as they are today, and many organizations were hesitant to adopt them due to concerns about their performance, support, and reliability.</p>
<p>&nbsp;</p>
<p><a href="https://codersee.com/newsletter/"><img fetchpriority="high" decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<p>As a result, MySQL quickly gained popularity among developers and organizations looking for an alternative to commercial database systems. Its success helped to pave the way for other open-source database systems, and it played a significant role in the growth of the open-source software movement as a whole.</p>
<p>Lastly, it&#8217;s worth mentioning that MySQL AB was bought by Sun Microsystems, which is now an Oracle Corporation (since 2010).</p>
<h2>What Is MySQL and How Does It Work?</h2>
<p>And although the previous chapter is a great MySQL introduction, let&#8217;s learn a bit more about it.</p>
<p>If I would have to answer the question &#8220;what is MySQL?&#8221; in one sentence, then I&#8217;d say that it is an <strong>open-source relational database management system. </strong>Moreover, according to the StackOverflow Developer Survey 2022, it&#8217;s the most popular RDBMS in the world. It is fast, reliable, and easy to use, making it an attractive choice for developers and organizations of all sizes.</p>
<p>MySQL is written in C++ and C and it was initially created from <strong>mSQL</strong> (aka <strong>M</strong>ini <strong>SQL</strong>), which is provided for non-commercial use. And although it gained a new SQL interface, the API remained the same making it easy to migrate from mSQL.</p>
<p>As a relational database, MySQL stores and organizes data in <strong>tables</strong>, which are grouped into <strong>databases</strong>. Each table consists of <strong>rows</strong> and <strong>columns</strong>. <strong>Rows</strong> represent individual pieces of data, while <strong>columns</strong> represent the different attributes of that data. And in order to query and manipulate the data from the database, we can use <strong>SQL queries</strong>. When it comes to storage, MySQL stores data in memory and on disk combining together performance and durability.</p>
<p>Finally, MySQL includes a number of other tools and features that make it easier to manage the database. These include utilities for security, performance tuning, backup, and recovery.</p>
<h2>MySQL &amp; LAMP</h2>
<p>It&#8217;s worth mentioning in our MySQL introduction, that MySQL is a part of the <strong>LAMP stack</strong>.</p>
<p><b>LAMP</b> is nothing else than an acronym for a proven set of technologies developers use to build websites and web applications:</p>
<ul>
<li><strong>Linux</strong> for the operating system</li>
<li><strong>Apache</strong> HTTP Server</li>
<li><strong>MySQL</strong> for the relational database management system</li>
<li><strong>PHP/Perl/Python</strong> programming language</li>
</ul>
<p>Not to mention you&#8217;re reading this article thanks to MySQL (used by WordPress).</p>
<h2>MySQL Advantages</h2>
<p>So, at this point, we know what is MySQL and as the next step, let&#8217;s figure out what it brings to the table:</p>
<ul>
<li><strong>MySQL is easy to use.</strong> It is known for being easy to install and use. Moreover, it has a simple and intuitive interface. This makes it not only a great choice for beginners, and less experienced teams, but also can bring lower costs for many companies.</li>
<li><strong>It&#8217;s open-source with a large and active community</strong>. MySQL is the most popular database in the world. And this advantage, combined with tons of documentation, blogs, and other resources available online, speeds up its integration, management, and debugging.</li>
<li><strong>Performance</strong>. And even though it might not be the best choice for large data sets, it&#8217;s still a multi-user and multi-threaded SQL server, which can handle millions of requests per day.</li>
<li><strong>Transactions support</strong>. Transactions, are an important feature of MySQL and allow us to ensure that the database remains in a consistent state, even if one of the operations fails.</li>
<li><strong>Flexibility</strong>. Lastly, MySQL supports multiple storage engines, which allows users to choose the best storage engine for their specific needs. Additionally, it supports a wide range of programming languages, making it easy to integrate into web-based applications and other systems.</li>
</ul>
<h2>MySQL Disadvantages</h2>
<p>And as with everything, MySQL has some drawbacks, as well:</p>
<ul>
<li><strong>Scaling complexity</strong>. Although MySQL can actually handle a lot of traffic, the scaling process requires manually sharding the data across multiple servers and configuring the servers to work together.</li>
<li><strong>Lack of certain security features</strong>. MySQL does not include certain security features, such as data masking and data classification, which are available in other database management systems.</li>
<li><strong>Limited support for distributed transactions.</strong> It does not have native support for distributed transactions.</li>
<li><strong>Commercial editions might be pricey.</strong> Although the open-source version of MySQL is free, the commercial editions of MySQL are licensed and can be expensive.</li>
</ul>
<h2>MySQL Use Cases</h2>
<p>As the next thing in our MySQL introduction, let&#8217;s see when it can be a good choice:</p>
<ul>
<li><strong>Web-based applications.</strong> MySQL is often used as the database backend for web-based applications. (And as mentioned previously, it&#8217;s a part of a LAMP stack).</li>
<li><strong>E-commerce</strong>. It&#8217;s a common choice for e-commerce platforms, due to its ability to handle large amounts of data and transactions support.</li>
<li><strong>Mobile applications</strong>. MySQL might be used as the database backend for mobile applications, as well.</li>
<li><strong>Internet Of Things</strong>. It can be used to store and manage data from IoT devices, such as sensors and connected devices.</li>
</ul>
<h2>Companies Using MySQL</h2>
<p>Lastly, let&#8217;s see a couple of companies, which use MySQL Database to deliver their products and services.</p>
<p>First of all, <strong>WordPress uses MySQL as its default database management system</strong>. Without it, you wouldn&#8217;t read this article 😉</p>
<p>Moreover, <strong>GitHub</strong> uses MySQL as its core data store. <strong>BBC</strong> makes use of the MySQL InnoDB Cluster and <strong>Uber </strong>claims that MySQL engine as the low-level storage layer has allowed them to very quickly build a robust system.</p>
<p>Of course, when we look at the list, we can find other known companies, like:</p>
<ul>
<li>Spotify</li>
<li>YouTube</li>
<li>Facebook</li>
<li>Sony</li>
<li>Airbnb and many more.</li>
</ul>
<p>If you&#8217;d like to learn more about other companies, then you can check out the <a href="https://www.mysql.com/customers/" target="_blank" rel="noopener">official customers&#8217; list.</a></p>
<h2>MySQL Introduction Conclusion</h2>
<p>And that&#8217;s all for this MySQL introduction, which is a continuation of a <strong>Top 8 Databases</strong> series. Together, we learned what is MySQL, its advantages, and disadvantages, as well, as its history and use cases.</p>
<p>If you are interested in Spring Boot, then you might want to check out my other articles with MySQL in practice and others under the <a href="https://blog.codersee.com/tag/mysql/">MySQL Tag</a>.</p>
<p>Finally, as always am <strong>happy to answer any questions and hear your thoughts</strong>. See you in the comments section!</p>
<p>The post <a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A Quick Intro To The 8 Most Popular Databases</title>
		<link>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/</link>
					<comments>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/#comments</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Wed, 14 Dec 2022 07:00:33 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Elasticsearch]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Microsoft SQL Server]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[SQLite]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504084</guid>

					<description><![CDATA[<p>Data is one of the most valuable assets of the XXI century and in this article, we will take a look at the 8 most popular databases of 2022.</p>
<p>The post <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">A Quick Intro To The 8 Most Popular Databases</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It won&#8217;t be a surprise if I say that <strong>data is one of the most valuable assets of the XXI century</strong>. Many organizations and businesses rely on the most popular databases to store, manage and analyze their data to support their business needs.</p>
<p>In this article, we will take a look at the <strong>8 most popular databases</strong> and their key features, as well as common use cases.</p>
<p>So, no matter whether you are a database administrator, programmer, or simply would like to learn more about the different databases available, this article will provide you with all the necessary information to start with.</p>
<h2>Doodly Animation</h2>
<p>If you find this content useful, please leave a <strong>thumb up</strong>, or a <strong>sub</strong>. This way you can help me, so that I can help you 😉</p>
<p>&nbsp;</p>
<div style="text-align: center;">
<a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2Fu81dp3igZVU%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<h2>What Does &#8220;The Most Popular Databases&#8221; Mean?</h2>
<p>Well, before we start I wanna make sure that we are on the same page when referring to the &#8220;most popular&#8221;.</p>
<p>Depending on who wrote the article, this term can have various meanings. For some, it will be the frequency of Google searches. For others, it may be data provided by the <a href="https://db-engines.com" target="_blank" rel="noopener">https://db-engines.com</a> page.</p>
<p>And for the purpose of this blog post, I decided to use the <a href="https://survey.stackoverflow.co/2022/" target="_blank" rel="noopener">Stack Overflow Developer Survey 2022 results</a>, which present, as follows:</p>
<p>&nbsp;</p>
<p><img decoding="async" class="aligncenter wp-image-5504088 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-1024x480.png" alt="The image is a screenshot of StackOverflow Developer Survey 2022 presenting the most popular databases: MySQL, PostgreSQL, SQLite, MongoDB, Microsoft SQL Server, Redis, MariaDB and ElasticSearch" width="800" height="375" srcset="https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-1024x480.png 1024w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-300x141.png 300w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-768x360.png 768w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey.png 1253w" sizes="(max-width: 800px) 100vw, 800px" /></p>
<p>&nbsp;</p>
<p>In the next chapters, I will walk you through each of the 8 most popular databases shortly.</p>
<p>Please keep in mind that this article is a general overview and expect that more thorough continuations will be added in the upcoming weeks 🙂</p>
<h2>MySQL Database</h2>
<p>With that being said, let&#8217;s start with the winner- <strong>MySQL</strong>.</p>
<p>It&#8217;s an open-source relational database management system (aka RDBMS). It was created in 1994 by the Swedish company <em>MySQL AB</em> (which was later acquired by <em>Sun Microsystems</em> and then by <em>Oracle Corporation</em>). Originally, it was developed as a proprietary database system but later it was open-sourced under the GNU General Public License.<br />
<a href="https://codersee.com/newsletter/"><img decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<h3>Advantages:</h3>
<ul>
<li><strong>It&#8217;s free and open-source,</strong> so it can be a great choice for smaller companies and organizations preferring to cut costs.</li>
<li>Moreover, MySQL <strong>is widely supported by web hosting providers,</strong> which means that it can be easily integrated with web-based applications.</li>
<li>Additionally, it has a <strong>low learning curve</strong> and a <strong>simple and intuitive user interface</strong>, so it is not only a great choice for beginners but also for less experienced teams.</li>
<li>Finally, <strong>a large and active community of users and developers </strong>means a lot of online resources and support available.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>First of all, <strong>it is not designed for applications that require real-time data processing or high availability</strong>. And technically- this is not a drawback, but rather something you should be aware of.</li>
<li>Whatsoever, MySQL is <strong>hard to scale</strong> and <strong>not intended for large amounts</strong> of data.</li>
<li>Lastly, <strong>it does not have built-in support for full-text search or geospatial data and some advanced features that are available in other database systems.</strong></li>
</ul>
<p>As I mentioned above, I will create a separate blog post about the king of the most popular databases. But for now, I can invite you to check out my other how-to guides with MySQL:</p>
<ul>
<li><a href="https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/">Deploy Kotlin Spring Boot App with MySQL on Kubernetes</a></li>
<li><a href="https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/">Spring Boot on Google GKE with Cloud SQL and Kotlin</a></li>
</ul>
<h2>PostgreSQL (aka Postgres)</h2>
<p>Nextly, let&#8217;s take a look at the second place with a 3% difference- <strong>PostgreSQL</strong> (also known as <strong>Postgres</strong>).</p>
<p>It was created in 1986 by a team of researchers at the University of California and is a <strong>powerful</strong> and <strong>open-source</strong> object-relational database management system. PostgreSQL is a highly popular and widely used DBMS, known for its flexibility, reliability, and performance.</p>
<h3>Advantages:</h3>
<ul>
<li>Just like MySQL, PostgreSQL is <strong>open-source</strong>, <strong>free to use, </strong>and<strong> has a large, active community.</strong></li>
<li>It is <strong>highly reliable</strong> and <strong>performs well even under heavy workloads</strong>. This makes it a good choice for applications that require high availability and scalability.</li>
<li>Moreover, Postgres comes with <strong>support for a lot of features and capabilities </strong>out of the box. For example triggers, stored procedures, and multi-row transactions.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Firstly, PostgreSQL <strong>may not be as widely supported</strong> or compatible with technologies, as some other database systems.</li>
<li>Secondly, it <strong>may not be as fast or scalable as other database management systems</strong>, such as NoSQL databases. And whereas it works well for large datasets, it is not the speed demon.</li>
<li>Whatsoever, Postgres is a pretty complex system, so <strong>it might be a bit difficult to learn</strong>.</li>
</ul>
<p>And just like previously, please expect new articles to come. But, again, if you would like to learn backend development with Kotlin and Postgres, then I can recommend:</p>
<ul>
<li><a href="https://codersee.com/courses/rest-api-with-spring-webflux-and-kotlin/">REST API With Spring WebFlux and Kotlin Course</a></li>
<li><a href="https://blog.codersee.com/tag/postgresql/">other tutorials on how to use it with Spring Boot, or Ktor</a></li>
</ul>
<h2>SQLite</h2>
<p>As the next step, let&#8217;s take a while to the no 3 in the most popular databases summary- <strong>SQLite</strong>.</p>
<p>SQLite is an embedded SQL database engine. The main difference between it and most of SQL databases is that it is self-contained and does not run a separate server process. To put it simply- it&#8217;s a library, which reads and writes directly to plain disk files.</p>
<p>It was created in 2000 by Dwayne Richard Hipp using a C programming language and since then, it become the most deployed database engine- used, among others of top web browsers.</p>
<h3>Advantages:</h3>
<ul>
<li>First of all, SQLite is a <strong>really lightweight</strong> database and it can be successfully used in low-memory environments. With all features enabled, its size can be as little as 750KiB.</li>
<li>Additionally, the database file format<strong> is portable</strong> and can be migrated between 32-bit ad 64-bit systems.</li>
<li>Moreover, SQLite is<strong> easy to learn</strong> and <strong>requires zero configuration</strong>, which makes it a great choice for beginners (and not only!)</li>
<li>Finally, it is <strong>really fast</strong> and can bring much better performance, than the filesystem.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Firstly- it&#8217;s <strong>not suitable for client/server applications</strong>. Although it can work over the network, the filesystem latency might be an issue.</li>
<li>Secondly (and lastly), SQLite <strong>is not a good choice for high-volume websites</strong> or environments demanding<strong> high concurrency</strong>. Whereas it does not have a limit for concurrent reads, only one writer can write at any instant in time.</li>
</ul>
<h2>MongoDB (aka Mongo)</h2>
<p>And the prize for 4th place in our most popular databases ranking goes to <strong>MongoDB</strong>.</p>
<p>MongoDB is an open-source document-oriented database. It was created in 2009 by MongoDB Inc., which makes it not only the first NoSQL representative in the ranking but also the youngest one (so far). In contrast to previous examples, MongoDB is an example of a NoSQL database, so instead of <em>tables</em> and <em>rows</em>, Mongo stores JSON-like <em>documents</em>, which are organized in <em>collections</em>.</p>
<h3>Advantages:</h3>
<ul>
<li>First of all, Mongo was built with environments demanding <strong>high performance</strong> and <strong>scalability </strong>in mind.</li>
<li>Secondly, it&#8217;s <strong>flexible</strong>. MongoDB does not require you to define a schema for your collections (SQL tables counterparts), which can help you reduce the time spent on schema changes. Moreover, it can be a great choice everywhere, where a schema is hard to define.</li>
<li>Finally, just like MySQL and Postgres, MongoDB is <strong>widely supported</strong> and really <strong>easy to learn</strong>.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>No <strong>out-of-the-box support for joins</strong>. Unlike relational databases, Mongo by design does not support joins between collections, so if you have to work with highly connected data sets, then it might not be the best choice.</li>
<li>Moreover, MongoDB documents <strong>cannot exceed 16MB.</strong></li>
<li>Lastly, the lack of joins oftentimes leads to <strong>data duplication</strong>, which may become troublesome to maintain in the future.</li>
</ul>
<p>If you would like to learn Mongo in practice, then check out my <a href="https://blog.codersee.com/tag/mongodb/">practical guides about MongoDB with Spring Boot, Ktor, and Micronaut</a>.</p>
<h2>Microsoft SQL Server</h2>
<p>Following, the 5th position on the most popular databases list is taken by <strong>Microsoft SQL Server</strong>.</p>
<p>It was developed by Microsoft and first released in 1989 and is another relational database in our ranking. Microsoft SQL Server lets us communicate using T-SQL (Transact-SQL), which is an extension of SQL bringing additional features, like functions, or local variables. Whatsoever, it comes with an entire range of products, which we can optionally configure together to make it a really powerful tool.</p>
<h3>Advantages:</h3>
<ul>
<li>Firstly, Microsoft SQL Server has really <strong>good support</strong> and <strong>documentation</strong>.</li>
<li>Additionally, it&#8217;s relatively <strong>easy to set up and use</strong>.</li>
<li>Whatsoever, SQL Server provides a range of <strong>security features</strong> to protect against unauthorized access to the data and <strong>ensure data integrity</strong>.</li>
<li>Lastly, a strong point is <strong>data recovery</strong> in case anything happens.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>First of all, <strong>pricing</strong>. And although there is a free option available, Enterprise or Standard editions are pretty expensive.</li>
<li>Secondly, <strong>compatibility</strong>. Prior to the SQL Server 2017, it could be run on Windows-based servers, but this is the first version, which can be deployed on Linux.</li>
<li>Lastly, it <strong>may require additional Microsoft software purchases</strong> to fully make use of it in your case.</li>
</ul>
<h2>Redis</h2>
<p>And the 6th most popular database of 2022 is <strong>Redis</strong>.</p>
<p>It was created by Salvatore Sanfilippo, also known as antirez, in 2009, which makes it a relatively young database in our summary.</p>
<p>Redis is an open-source, in-memory data structure store that is commonly used as a database, cache, and message broker. It is known for its high performance, flexibility, and scalability, making it a popular choice for a wide range of applications. Whatsoever, it is oftentimes used in conjunction with Microservices and containers, to support the needs of modern, distributed applications.</p>
<h3>Advantages:</h3>
<ul>
<li>As the first one- Redis is an <strong>in-memory data store</strong>, which results in much higher data processing, than disk-based databases.</li>
<li>Additionally, it&#8217;s <strong>highly scalable</strong> and <strong>can be easily expanded</strong> to support the growing needs of our application.</li>
<li>Lastly, Redis is an <strong>open-source</strong> project with a<strong> large community</strong> and a<strong> huge amount of online resources</strong> to use and learn from. Moreover, <strong>it is compatible</strong> and pretty<strong> easy to use with most of the popular frameworks</strong>.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>So the first advantage is the disadvantage, as well. The in-memory data store is actually faster, but we have to keep in mind that it is <strong>more expensive</strong>.</li>
<li>Moreover, it is a key-value store (like a dictionary), which means that the application(s) connecting to Redis <strong>have to be aware of the structure</strong>, which requires additional config.</li>
<li>Lastly, Redis is doing fine when dealing with key-based operations, but <strong>is not that efficient, when it comes to searching through the data set</strong>.</li>
</ul>
<p>If you would like to learn more about it in detail, then check out my more detailed article: <a href="https://blog.codersee.com/redis-database-explained/">Redis Database Explained</a></p>
<h2>MariaDB</h2>
<p>As the one before last in the most popular databases list, let&#8217;s see what exactly <strong>MariaDB</strong> is.</p>
<p>First of all, MariaDB is a fork of the MySQL DBMS, created by the original developers of MySQL in response to the acquisition of MySQL by Oracle Corporation. The acquisition raised concerns among many users and developers about the future direction of the MySQL project, which resulted in MariaDB being released in 2009.</p>
<p>It&#8217;s known for its performance, reliability, and ease of use, and is used by many organizations around the world. Moreover, it is designed to be backward-compatible with MySQL and can be used as a drop-in replacement for it in most cases.</p>
<h3>Advantages:</h3>
<ul>
<li>Firstly, MariaDB is known for its <strong>performance</strong> and <strong>reliability</strong>.</li>
<li>Additionally, it is an<strong> open-source</strong> project with a <strong>large</strong> and <strong>active community</strong> of users and developers. And I know that this argument repeats often in this article. But trust me- a wealth of resources, such as documentation and tutorials, available online comes with plenty of other perks.</li>
<li>Thirdly, as mentioned above <strong>it can be used as a MySQL drop-in replacement in most cases</strong>. This allows companies to replace the database without changing the other tools. However, please remember that this is not always the case and sometimes may require additional work.</li>
<li>And lastly, it is <strong>widely supported</strong> by various programming languages and frameworks.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>As the first one, <strong>some of the MySQL Enterprise Edition features are not available out of the box</strong>. And although this can be done through plugins, this is an additional, independent tool we have to incorporate.</li>
<li>Whatsoever, <strong>migrating from MySQL may result in additional adjustments and config</strong>.</li>
<li>And as the last thing- <strong>the support may be pretty expensive</strong>.</li>
</ul>
<h2>Elasticsearch</h2>
<p>And finally, we come to the last position in the top 8 most popular databases of 2022- <strong>Elasticsearch</strong>.</p>
<p>Elasticsearch is an open-source, full-text search and analytics engine created by Shay Banon in 2010.</p>
<p>It is designed to be scalable and flexible, making it a popular choice for building search and data analysis applications. Moreover, it&#8217;s based on the Lucene search engine library and provides a RESTful API for interacting with the data. Elasticsearch is known for its powerful search and analytics capabilities, and can be used to search, analyze, and visualize data from a variety of sources, including structured, unstructured, and time-series data.</p>
<h3>Advantages:</h3>
<ul>
<li>Elasticsearch is an <strong>open-source</strong> project, supported by a<strong> large and active community of users</strong>.</li>
<li>Similarly, it&#8217;s <strong>compatible with plenty of programming languages and frameworks</strong>, which helps in its implementation.</li>
<li>Lastly, it is a <strong>highly scalable search and analytics engine</strong>, which is intended for fast full-text searches. Thus, it can be a great solution for website searches.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Elasticsearch <strong>may not be as fast or efficient as some other search and analytics platforms</strong> in certain scenarios- for example, a large amount of data.</li>
<li>Moreover, it <strong>is more difficult to learn</strong> compared to similar tools. But this comes with being more powerful, as well.</li>
<li>Lastly, Elasticsearch <strong>should not be used as primary storage</strong>.</li>
</ul>
<h2>The Most Popular Databases Summary</h2>
<p>And that&#8217;s all for this article about the 8 most popular databases. As I already mentioned, this is the initial, bird&#8217;s-eye view post and you can expect more detailed articles to come.</p>
<p>Let me know your thoughts in the comments section below!</p>
<p>The post <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">A Quick Intro To The 8 Most Popular Databases</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Deploy Kotlin Spring Boot App with MySQL on Kubernetes</title>
		<link>https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/</link>
					<comments>https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Thu, 22 Oct 2020 07:50:57 +0000</pubDate>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<guid isPermaLink="false">http://codersee.com/?p=1542</guid>

					<description><![CDATA[<p>In this article, we will learn how to deploy the Kotlin Spring Boot application with MySQL on Kubernetes cluster.</p>
<p>The post <a href="https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/">Deploy Kotlin Spring Boot App with MySQL on Kubernetes</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 class="article-heading-introduction">1. Introduction</h2>
<p><a href="http://codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/" target="_blank" rel="noopener noreferrer">Last week</a>, we&#8217;ve learned how to deploy the <strong>Spring Boot</strong> application to <strong>Google Kubernetes Engine</strong> and connect it to the <strong>CloudSQL</strong> instance of <strong>MySQL</strong> database.</p>
<p>This time, I want to show you a more universal approach- deploying the <strong>Kotlin Spring Boot App with MySQL directly on Kubernetes</strong>. This approach requires a little more setup, but thanks to that, we gain more independence- we can easily migrate our environment between Kubernetes managed services providers (or to self-hosted k8s).</p>
<h2 class="article-heading-main">2. Prerequisites</h2>
<p>To follow the tutorial you need the following prerequisites:</p>
<ul>
<li><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/" target="_blank" rel="noopener noreferrer">kubectl</a> (Kubernetes CLI to manage a cluster)</li>
<li><a href="https://minikube.sigs.k8s.io/docs/start/" target="_blank" rel="noopener noreferrer">minikube</a> (local Kubernetes, making it easy to learn and develop for Kubernetes)</li>
<li><a href="https://docs.docker.com/engine/install/" target="_blank" rel="noopener noreferrer">docker</a> (containerization tool)</li>
</ul>
<h2 class="article-heading-main">3. Create Spring Boot Application</h2>
<p>In this tutorial, I&#8217;d like to begin with developing our <strong>Spring Boot app</strong> first (but it&#8217;s also OK to start with the Kubernetes part).</p>
<h3 class="article-heading-sub">3.1. Imports</h3>
<p>As the first step, let&#8217;s add the following dependencies:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="groovy">    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    runtimeOnly("mysql:mysql-connector-java")
</pre>
<p>Please remember, that you can see the full <a href="https://github.com/codersee-blog/kotlin-spring-boot-mysql-k8s/blob/master/build.gradle.kts" target="_blank" rel="noopener noreferrer">build.gradle configuration here</a>.</p>
<h3 class="article-heading-sub">3.2. Configure Application Properties</h3>
<p>After we&#8217;ve successfully added the import, let&#8217;s head to the <strong>application.yaml</strong> file and configure it as follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">spring:
  datasource:
    url: jdbc:mysql://mysql-svc:3306/${DB_NAME}?useSSL=false
    username: ${DB_USERNAME}
    password: ${DB_PASSWORD}
  jpa:
    hibernate:
      ddl-auto: update
    databasePlatform: "org.hibernate.dialect.MySQL5InnoDBDialect"
</pre>
<p>As you might have noticed, we are setting the <em>MySQL connection details</em> here. Please remember, that the host (<em><strong>mysql-svc</strong></em>) has to match the MySQL Kubernetes service name (we will set it up later). The <em><strong>ddl-auto</strong></em> property set to <em><strong>update</strong></em> will automatically export the schema DDL to the database when the SessionFactory is created (to put it simply, it will create the database schema based on our Spring Boot entities).</p>
<h3 class="article-heading-sub">3.2. Create Model</h3>
<p>As the next step, let&#8217;s add two classes to our project. <strong>User</strong> class, which will be the user entity we will persist in our MySQL database:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@Entity
class User(
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long = 0,

    @Column
    val name: String
)
</pre>
<p>As you can see, it is a simple class containing two fields- autogenerated <em>id</em> and a<em> name</em>.</p>
<p>Nextly, let&#8217;s add <strong>UserRequest</strong>, which will be bound to the bodies of the web requests later:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">class UserRequest(
    val name: String
)
</pre>
<h3 class="article-heading-sub">3.4. Create Repository</h3>
<p>After that, we can create the <strong>UserRepository</strong> interface, which will be used to perform the operations on the database:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">interface UserRepository : CrudRepository&lt;User, Long&gt;
</pre>
<h3 class="article-heading-sub">3.4. Create Service</h3>
<p>As the next step, let&#8217;s implement the <strong>UserService</strong> class as follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@Service
class UserService(
    private val userRepository: UserRepository
) {

    fun saveUser(request: UserRequest): User =
        userRepository.save(
            User(
                name = request.name
            )
        )

    fun findAllUsers(): MutableIterable&lt;User&gt; =
        userRepository.findAll()
}
</pre>
<p>These two functions will be responsible for creating and getting the list of all users.</p>
<h3 class="article-heading-sub">3.5. Implement Controllers</h3>
<p>Finally, we can set up our controllers responsible for handling the incoming requests. Let&#8217;s start by adding the <strong>ApiStatusController</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@RestController
@RequestMapping("/api/status")
class ApiStatusController {
    @GetMapping
    fun getStatus(): ResponseEntity = ResponseEntity.ok("OK")
}
</pre>
<p>The <strong>GET /api/status</strong> endpoint will be used later to configure our <strong>K8s</strong> Pod&#8217;s readiness and liveness probes.</p>
<p>As the last step, let&#8217;s create the <strong>UserController</strong> class:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@RestController
@RequestMapping("/api/user")
class UserController(
    private val userService: UserService
) {
    @PostMapping
    fun createUser(@RequestBody request: UserRequest): ResponseEntity {
        val user = userService.saveUser(request)

        return ResponseEntity.ok(user)
    }

    @GetMapping
    fun findAllUsers(): ResponseEntity&lt;MutableIterable&gt; {
        val users = userService.findAllUsers()

        return ResponseEntity.ok(users)
    }
}
</pre>
<p>These two functions will be responsible for responding to the <strong>POST</strong> and <strong>GET</strong> requests to the<strong> /api/user</strong> endpoint. As you can see, we are using here the <strong>UserRequest</strong> class, we&#8217;ve implemented earlier as the <em><strong>createUser</strong></em> method parameter.</p>
<h3 class="article-heading-sub">3.6. Build the JAR</h3>
<p>Let&#8217;s build the jar with the Gradle wrapper:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">./gradlew clean build -x test
</pre>
<p>Please notice <strong>&#8220;-x test&#8221;</strong> flag here. Testing goes beyond the main topic of this tutorial, so I&#8217;ve decided to go with this workaround for now.</p>
<h3 class="article-heading-sub">3.7. Create Dockerfile</h3>
<p>Nextly, let&#8217;s create the <strong>Dockerfile</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">FROM openjdk
WORKDIR /work
COPY ./build/libs/k8s-mysql-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/work/app.jar"]
</pre>
<h2 class="article-heading-main">4. Deploy to Kubernetes</h2>
<p>In this part, we are going to prepare the <strong>Kubernetes</strong> environment for our <strong>Spring Boot application</strong>. To keep this article as pragmatic as possible, we won&#8217;t spend too much time on the details here. If you would like to get a better understanding of these topics, please, let me know about it and I will prepare more materials about it.</p>
<h3 class="article-heading-sub">4.1. Create Secrets</h3>
<p>As the first step, let&#8217;s create the <strong>secrets.yaml</strong> file and put the configuration for our secrets here:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: v1
kind: Secret
data:
  root-password: &lt;BASE64-ENCODED-PASSWORD&gt;
  database-name: &lt;BASE64-ENCODED-DB-NAME&gt;
  user-username: &lt;BASE64-ENCODED-DB-USERNAME&gt;
  user-password: &lt;BASE64-ENCODED-DB-PASSWORD&gt;
metadata:
  name: mysql-secret
</pre>
<p>In simple words, <strong>secrets</strong> let us store and manage sensitive information in a secure manner.<br />
Please also notice that all of the values should be encoded as<strong> base 64</strong>. You can do that for instance <a href="https://www.base64encode.org/" target="_blank" rel="noopener noreferrer">on this website.</a></p>
<h3 class="article-heading-sub">4.2. Create Persistent Volume</h3>
<p>As the next step, let&#8217;s create the <strong>deployment-mysql.yaml</strong> file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
  labels:
    type: local
spec:
  storageClassName: standard
  capacity:
    storage: 250Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
  persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
  labels:
    app: spring-boot-mysql
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 250Mi
</pre>
<p>A <strong>PersistentVolume (PV)</strong> is a piece of the storage in the cluster, while the <strong>PersistentVolumeClaim (PVC)</strong> is the request for storage.</p>
<h3 class="article-heading-sub">4.3. Create MySQL Deployment</h3>
<p><strong>Deployments</strong> allow us to provide updates for our <strong>Pods</strong> and <strong>ReplicaSets</strong> in a declarative manner. To configure the MySQL database let&#8217;s add the following config to our <strong>deployment-mysql.yaml</strong> file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
  labels:
    app: spring-boot-mysql
spec:
  selector:
    matchLabels:
      app: spring-boot-mysql
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: spring-boot-mysql
        tier: mysql
    spec:
      containers:
        - image: mysql:5.7
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: root-password
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: database-name
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: user-username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: user-password
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc
</pre>
<p>As you can see above, we are passing our 4 secrets to the MySQL container as the environment variables- these values will be used for our connection.</p>
<h3 class="article-heading-sub">4.4. Create MySQL Service</h3>
<p>Finally, we need to expose the database for our <strong>Spring Boot application</strong>. Let&#8217;s do that by creating the <strong>service-mysql.yaml</strong> file and putting the following confirugation:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: v1
kind: Service
metadata:
  name: mysql-svc
  labels:
    app: spring-boot-mysql
spec:
  ports:
    - port: 3306
  selector:
    app: spring-boot-mysql
    tier: mysql
  clusterIP: None
</pre>
<p>Please notice, that the <em><strong>name</strong></em> property of the metadata has to match the value from the <strong>application.yaml</strong> file of the<strong> Spring Boot</strong> project.</p>
<h3 class="article-heading-sub">4.5. Create Spring Boot Deployment</h3>
<p>After the <strong>MySQL</strong> part is correctly set up, we can configure the resources for our application. Let&#8217;s start by creating the <strong>deployment-spring.yaml</strong> file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-boot-deployment
  labels:
    app: spring-boot-mysql
spec:
  replicas: 2
  selector:
    matchLabels:
      app: spring-boot-mysql
  template:
    metadata:
      labels:
        app: spring-boot-mysql
    spec:
      containers:
        - image: spring-boot:0.0.1
          name: spring-boot-container
          imagePullPolicy: Never 
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              port: 8080
              path: /api/status
            initialDelaySeconds: 10
            failureThreshold: 5
          livenessProbe:
            httpGet:
              port: 8080
              path: /api/status
            initialDelaySeconds: 10
            failureThreshold: 5
          env:
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: database-name
            - name: DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: user-username
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: user-password
</pre>
<p>Please notice one important thing here- in the next steps, I will show you how to use the <strong>local Spring Boot Docker image</strong> of our application. That&#8217;s why we&#8217;ve set the <em><strong>imagePullPolicy</strong></em> property to <em><strong>Never</strong></em>.</p>
<h3 class="article-heading-sub">4.6. Create Spring Boot Service</h3>
<p>The last thing, we need to configure for our backend is a <strong>Service</strong>. Let&#8217;s create then the <strong>service-spring.yaml</strong> file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: v1
kind: Service
metadata:
  name: spring-boot-svc
spec:
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
      name: http
  selector:
    app: spring-boot-mysql
  type: LoadBalancer
</pre>
<h3 class="article-heading-sub">4.7. Apply and Verify Resources</h3>
<p>Finally, we can deploy our configurations to the <strong>Kubernetes</strong> cluster. As the first step, let&#8217;s start a <strong>local</strong> <strong>Kubernetes</strong> <strong>cluster</strong> with <em><strong>minikube</strong></em>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">minikube start --vm-driver=virtualbox
</pre>
<p>As I&#8217;ve mentioned in step<strong> 4.5</strong>, in this tutorial, we will use the local docker image without pushing to any remote image repository.</p>
<p>To do that, let&#8217;s <strong>reuse the Docker daemon from Minikube</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">eval $(minikube docker-env)
</pre>
<p>Please keep in mind, that this is a <strong>Unix</strong> command. If you are using Windows OS, please check out <a href="https://stackoverflow.com/questions/1195494/equivalent-to-unix-eval-in-windows" target="_blank" rel="noopener noreferrer">this StackOverflow topic</a>.</p>
<p>Nextly, let&#8217;s build our docker image:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">docker build -t spring-boot:0.0.1 .
</pre>
<p>Please remember, that the tag has to match the value from our<strong> Spring Boot deployment</strong>.</p>
<p>As the last step, let&#8217;s apply our configurations:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/deployment-mysql.yaml 
kubectl apply -f k8s/service-mysql.yaml
kubectl apply -f k8s/deployment-spring.yaml
kubectl apply -f k8s/service-spring.yaml
</pre>
<p>To verify if everything is ready, we can use the following commands:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl get svc
kubectl get deployments
kubectl get pods
kubectl get secrets
</pre>
<h2 class="article-heading-main">5. Verify the Application</h2>
<p>To verify, if the application is working correctly, we will have to get the IP address of the running cluster and the port of the Spring Boot Service.</p>
<p>We can obtain the IP address in two ways: either by minikube or using kubectl command:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">minikube ip
//result
192.168.39.87


kubectl cluster-info
//result
Kubernetes master is running at https://192.168.39.87:8443
</pre>
<p>To get the port of the application, let&#8217;s invoke the following command:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl get svc spring-boot-svc 

//Example response
NAME              TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
spring-boot-svc   LoadBalancer   10.107.222.166        8080:30264/TCP   33s
</pre>
<p>As you can see above, the desired port of the application will be <strong>30264</strong>. Please keep in mind, that this value will be different each time we will create the <strong>Service</strong>.</p>
<p>Finally, let&#8217;s create the user using the curl command:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">curl -X POST -H "Content-Type: application/json" \
  --data '{"name":"Piotr"}' \
  192.168.39.87:30264/api/user

//response
{"id":1,"name":"Piotr"}
</pre>
<p>As the last step, let&#8217;s get the list of all users:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">curl 192.168.39.87:30264/api/user

//Response:
[{"id":1,"name":"Piotr"}]
</pre>
<h2 class="article-heading-main">6. Summary</h2>
<p>And that would be all for this article. In this step by step guide, we&#8217;ve learned how to deploy the<strong> Spring Boot and MySQL</strong> application on <strong>Kubernetes</strong>.</p>
<p>I am really aware that this topic is quite complex and requires an understanding of several concepts. The main goal for this tutorial was to walk you through the whole process without diving too much into the details. If you find anything in this article confusing or have any additional questions/suggestions, I will be more than happy if you would let me know about it (you can do that by our <a href="https://www.facebook.com/codersee/" target="_blank" rel="noopener noreferrer"><strong>fan page</strong></a>, <a href="https://www.facebook.com/groups/622361565094117" target="_blank" rel="noopener noreferrer"><strong>group</strong></a>, or a <strong><a href="http://codersee.com/contact/" target="_blank" rel="noopener noreferrer">contact</a> </strong>form).</p>
<p>To see the whole project, please visit <a href="https://github.com/codersee-blog/kotlin-spring-boot-mysql-k8s" target="_blank" rel="noopener noreferrer">this GitHub repository</a>.</p>
<p>The post <a href="https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/">Deploy Kotlin Spring Boot App with MySQL on Kubernetes</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Spring Boot on Google GKE with Cloud SQL and Kotlin</title>
		<link>https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/</link>
					<comments>https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/#comments</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Thu, 15 Oct 2020 09:50:39 +0000</pubDate>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Cloud SQL]]></category>
		<category><![CDATA[Google Cloud]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<guid isPermaLink="false">http://codersee.com/?p=1495</guid>

					<description><![CDATA[<p>In this article, I'd like to show you how to deploy Spring Boot Kotlin application to the GKE with Cloud SQL using sidecar pattern.</p>
<p>The post <a href="https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/">Spring Boot on Google GKE with Cloud SQL and Kotlin</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 class="article-heading-introduction">1. Introduction</h2>
<p>In <a href="http://codersee.com/deploy-spring-boot-application-to-gke/" target="_blank" rel="noopener noreferrer">one of my past articles</a>, we&#8217;ve learned how to deploy the <strong>Spring Boot Kotlin</strong> application to the <strong>Google Kubernetes Engine</strong>. According to your feedback, you really enjoyed it and some of you asked me to write something more about connecting to the databases in such an environment.</p>
<p>In the beginning, I&#8217;d like to thank you so much for the inspiration. You can be sure, that in the future I will prepare more articles on this topic.</p>
<p>In this guide, I&#8217;d like to show you how to deploy <strong>Spring Boot Kotlin</strong> application to the <strong>GKE with Cloud SQL</strong> using a sidecar pattern. It will be the continuation of <a href="http://codersee.com/deploy-spring-boot-application-to-gke/" target="_blank" rel="noopener noreferrer">this post</a>, so I highly recommend spending some time checking it.</p>
<h2 class="article-heading-main">2. Create Cloud SQL Instance</h2>
<p>As the first step, let&#8217;s head to the <a href="https://console.cloud.google.com/sql/" target="_blank" rel="noopener noreferrer">GCP Cloud SQL console</a> and click the <strong>Create Instance</strong> button.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1514" src="http://blog.codersee.com/wp-content/uploads/2020/10/1-1.png" alt="This image cotnains the screenshot from cloud sql create instance page" width="537" height="301" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/1-1.png 537w, https://blog.codersee.com/wp-content/uploads/2020/10/1-1-300x168.png 300w" sizes="auto, (max-width: 537px) 100vw, 537px" /></p>
<p>On the next page, let&#8217;s select the <strong>MySQL database</strong>:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1515" src="http://blog.codersee.com/wp-content/uploads/2020/10/2-1.png" alt="Photo shows the screenshot from cloud sql select database page" width="483" height="315" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/2-1.png 483w, https://blog.codersee.com/wp-content/uploads/2020/10/2-1-300x196.png 300w" sizes="auto, (max-width: 483px) 100vw, 483px" /></p>
<p>Let&#8217;s provide the <em>instance ID</em> and<em> root password</em> for our database. As you can see on the below screenshot, we can also specify other things, like <em>region</em>, <em>zone</em>, or <em>database</em> version:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1516" src="http://blog.codersee.com/wp-content/uploads/2020/10/3-3.png" alt="The photo shows the screenshot from configure instance info page" width="462" height="515" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/3-3.png 462w, https://blog.codersee.com/wp-content/uploads/2020/10/3-3-269x300.png 269w" sizes="auto, (max-width: 462px) 100vw, 462px" /></p>
<p>Finally, let&#8217;s click the <strong>Create</strong> button and start the process of creating the instance.</p>
<h2 class="article-heading-main">3. Create a Service Account</h2>
<p>As the next step, let&#8217;s switch to the <a href="https://console.cloud.google.com/iam-admin/serviceaccounts" target="_blank" rel="noopener noreferrer">service accounts panel</a> of the IAM management. We need to prepare the service account, which will be used later to establish the connection between the <strong>GKE</strong> and <strong>Cloud SQL</strong>.</p>
<p>Let&#8217;s click the <strong>Create Service Account</strong> button. Then, let&#8217;s specify the service account name and click <strong>Create</strong>:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1517" src="http://blog.codersee.com/wp-content/uploads/2020/10/5-1.png" alt="The image contains the screenshot showing how to provide the service account name for the cloud sql service account" width="620" height="426" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/5-1.png 620w, https://blog.codersee.com/wp-content/uploads/2020/10/5-1-300x206.png 300w" sizes="auto, (max-width: 620px) 100vw, 620px" /></p>
<p>Nextly, let&#8217;s grant the <em><strong>Cloud SQL Admin Role</strong></em> to our service account:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1518" src="http://blog.codersee.com/wp-content/uploads/2020/10/6-1.png" alt="The image shows the screenshot from the console showing how to add Cloud SQL Admin role to the service account" width="533" height="313" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/6-1.png 533w, https://blog.codersee.com/wp-content/uploads/2020/10/6-1-300x176.png 300w" sizes="auto, (max-width: 533px) 100vw, 533px" /></p>
<p>Please note: for the tutorial, we are using the admin role, but in the real-life scenarios we should always remember about the <strong>Principle of Least Privilege (POLP)</strong>.</p>
<h2 class="article-heading-main">4. Enable Cloud SQL Admin API</h2>
<p>Before we will be able to connect using the Cloud SQL Proxy, we need to enable the Cloud SQL Admin API. To do that, let&#8217;s head to the <a href="https://console.developers.google.com/apis/library/sqladmin.googleapis.com" target="_blank" rel="noopener noreferrer">API management page</a> and click the Enable button:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1520" src="http://blog.codersee.com/wp-content/uploads/2020/10/api-enable.png" alt="The image shows how to enable the Cloud SQL Admin API" width="515" height="256" srcset="https://blog.codersee.com/wp-content/uploads/2020/10/api-enable.png 515w, https://blog.codersee.com/wp-content/uploads/2020/10/api-enable-300x149.png 300w" sizes="auto, (max-width: 515px) 100vw, 515px" /></p>
<h2 class="article-heading-main">5. Connecting Using the Cloud SQL Proxy</h2>
<p>There are a few approaches on how to connect to our SQL instance. For a better understanding of the topic, I highly recommend checking out <a href="https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine" target="_blank" rel="noopener noreferrer">this Google guide</a>.</p>
<p>In this tutorial, we will add the proxy to our application&#8217;s pod using the <em>sidecar container pattern</em>. If you would be interested in tutorials covering other ways of connection, please let me know about it.</p>
<h3 class="article-heading-sub">5.1. Add Proxy Container</h3>
<p>Let&#8217;s start by adding the proxy to the deployment file. Let&#8217;s head to the previously created <strong>deployment.yaml</strong> file and put the following config under the <em><strong>containers</strong></em>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">- image: gcr.io/cloudsql-docker/gce-proxy:1.18.0
  name: cloud-sql-proxy
  command:
    - "/cloud_sql_proxy"
    - "-instances=&lt;PROJECT_ID&gt;:&lt;ZONE&gt;:&lt;INSTANCE_NAME&gt;=tcp:3306"
  securityContext:
    runAsNonRoot: true
</pre>
<p>The second command in our configuration requires us to specify the list of comma-separated fully qualified instances connections names. You can check your connection name in the <a href="https://console.cloud.google.com/sql/" target="_blank" rel="noopener noreferrer">Cloud SQL console</a>.</p>
<h3 class="article-heading-sub">5.2. Connect Service Account</h3>
<p>As the next step, we will provide the service account for our proxy. We will do it using <strong>GKE&#8217;s Workload Identity feature</strong>, which is the preferred method. To put it simply, we will bind the <strong>Kubernetes Service Account (KSA)</strong> to a <strong>Google Service Account (GSA)</strong>.</p>
<p>Let&#8217;s start by enabling the Workload Identity on our existing cluster:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">gcloud container clusters update  \
  --workload-pool=&lt;PROJECT-ID&gt;.svc.id.goog
  --zone=&lt;ZONE&gt;
</pre>
<p>We will need to wait for some time for the changes to be applied.</p>
<p>Nextly, let&#8217;s create the <strong>service-account.yaml</strong> file and put there the configuration for the KSA:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">apiVersion: v1
kind: ServiceAccount
metadata:
  name: cloud-sql-sa
</pre>
<p>And create the KSA in our cluster:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl apply -f service-account.yaml</pre>
<p>With that being done, we can enable the IAM binding between the<strong> &lt;GSA-NAME&gt;</strong> and<strong> &lt;KSA-NAME&gt;</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">gcloud iam service-accounts add-iam-policy-binding \
  --role roles/iam.workloadIdentityUser \
  --member "serviceAccount:&lt;PROJECT-ID&gt;.svc.id.goog[&lt;K8S-NAMESPACE&gt;/&lt;KSA-NAME&gt;]" \
  &lt;GSA-NAME&gt;@&lt;PROJECT-ID&gt;.iam.gserviceaccount.com
</pre>
<p>As the next step, let&#8217;s add an annotation to <strong>&lt;KSA-NAME&gt;</strong> to complete the binding:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl annotate serviceaccount \
   &lt;KSA-NAME&gt; \
   iam.gke.io/gcp-service-account=&lt;GSA-NAME&gt;@&lt;PROJECT-ID&gt;.iam.gserviceaccount.com
</pre>
<p>Finally, please make sure to specify the service account for the Kubernetes object:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">spec:
  serviceAccountName: cloud-sql-sa
</pre>
<h2 class="article-heading-main">6. Configure Spring Boot App</h2>
<p>After all the above steps, we can finally switch to our <strong>Spring Boot</strong> project to set up the connection.</p>
<h3 class="article-heading-sub">6.1. Imports</h3>
<p>Let&#8217;s start by adding necessary imports:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">    runtimeOnly("mysql:mysql-connector-java")
</pre>
<p>As you can see, we are adding <strong>MySQL Connector dependency</strong>. If we had chosen another database in step 2, we would have to import the appropriate driver here.</p>
<h3 class="article-heading-sub">6.2. Edit Application Properties</h3>
<p>As the next step, let&#8217;s edit the <strong>application.yaml</strong> file and put the following configuration there:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/${DB_NAME}
    username: ${DB_USERNAME}
    password: ${DB_PASSWORD}
</pre>
<p>Please notice, that the environment variables should be set to, or replaced with the correct values. For the learning purposes, as the user, we can use root with the password we&#8217;ve set in step 2. Also, to create the database, we can head to the <a href="https://console.cloud.google.com/sql/instances/mysql-instance1/databases" target="_blank" rel="noopener noreferrer">Cloud SQL Databases console</a>.</p>
<h2 class="article-heading-main">7. Deploy Spring Boot App to GKE</h2>
<p>As the last step, let&#8217;s deploy our application to the<strong> Google Kubernetes Engine</strong>. Let&#8217;s build and push our container with the following commands:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">docker build -t spring-boot-example .
docker tag spring-boot-example gcr.io//spring-boot-example:0.0.2
docker push gcr.io//spring-boot-example:0.0.2
</pre>
<p>Please notice, that you can use the tag whatever you like. I&#8217;m just using <em><strong>0.0.2</strong></em> to keep it concise with the previous article.</p>
<p>Finally, let&#8217;s update our deployment file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">containers:
  - image: gcr.io//spring-boot-example:0.0.2
</pre>
<p>And submit our changes to the cluster:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl apply -f deployment.yaml</pre>
<p>After all, we can check the status of changes, for instance with the get pods command:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">kubectl get pods

//example response
NAME                                   READY   STATUS    RESTARTS   AGE
spring-boot-example-799bb5dd97-whwdb   2/2     Running   0          55s
</pre>
<p>As you can see, the Pod is running and both containers are ready.</p>
<h2 class="article-heading-main">8. Summary</h2>
<p>And that would be all for this article. We&#8217;ve covered step by step how to deploy the <strong>Spring Boot application</strong> to the<strong> Google Kubernetes Engine</strong> with <strong>Cloud SQL</strong>. I believe, that some of the steps may seem pretty difficult, but I can guarantee you that over time, you will get a much better understanding of this topic.</p>
<p>Hope you had a great time reading this article. Please remember, that you can always contact me through the <a href="https://www.facebook.com/codersee/" target="_blank" rel="noopener noreferrer"><strong>fan page</strong></a>, <a href="https://www.facebook.com/groups/622361565094117" target="_blank" rel="noopener noreferrer"><strong>group</strong></a>, or <strong><a href="http://codersee.com/contact/" target="_blank" rel="noopener noreferrer">contact</a> </strong>form. Don&#8217;t be afraid to ask any questions- I will be more than happy to answer them.</p>
<p>And of course, you can find the full source code <a href="https://github.com/codersee-blog/kotlin-spring-boot-gke-cloud-sql" target="_blank" rel="noopener noreferrer"><strong>here</strong></a>.</p>
<p>The post <a href="https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/">Spring Boot on Google GKE with Cloud SQL and Kotlin</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: blog.codersee.com @ 2026-05-02 11:53:49 by W3 Total Cache
-->