<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mario Netto</title>
    <description>The latest articles on DEV Community by Mario Netto (@marionettoc).</description>
    <link>https://dev.to/marionettoc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F548761%2Face0ac82-c646-48d5-b4d3-6072531d5876.jpg</url>
      <title>DEV Community: Mario Netto</title>
      <link>https://dev.to/marionettoc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marionettoc"/>
    <language>en</language>
    <item>
      <title>Run MySQL in Docker on Windows</title>
      <dc:creator>Mario Netto</dc:creator>
      <pubDate>Fri, 12 Apr 2024 18:47:33 +0000</pubDate>
      <link>https://dev.to/marionettoc/run-mysql-in-docker-on-windows-41a3</link>
      <guid>https://dev.to/marionettoc/run-mysql-in-docker-on-windows-41a3</guid>
      <description>&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Resolving MySQL/MariaDB database and table name case sensitivity on Windows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Details
&lt;/h2&gt;

&lt;p&gt;I develop locally on my Windows 10 laptop. When I started my first project that used MySQL as the backend, I installed MySQL on my Windows but noticed that the database and table names were created in lower case. However, the same SQL scripts were creating them with intended casing in AWS RDS.&lt;/p&gt;

&lt;p&gt;Here is a sample SQL script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="nv"&gt;`Sandbox`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;USE&lt;/span&gt; &lt;span class="nv"&gt;`Sandbox`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="nv"&gt;`MyTable`&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nv"&gt;`Id`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;`Name`&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;InnoDB&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;CHARSET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;utf8mb4&lt;/span&gt; &lt;span class="k"&gt;COLLATE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;utf8mb4_general_ci&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running this script in MySQL on Windows creates the following as shown in this screenshot from MySQL Workbench. Database and table names in lower case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajl8vnco42kpi550ncd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajl8vnco42kpi550ncd8.png" alt="MySQL Workbench showing database and table names in lower case" width="166" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To resolve this, I chose to go the Docker route and install/run MySQL from within a Linux Docker container on Windows.&lt;/p&gt;

&lt;p&gt;Here are the steps I took to get this working.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit &lt;a href="https://docs.docker.com/desktop/install/windows-install/"&gt;Docker Desktop on Windows&lt;/a&gt; for detailed steps. Check your machine configuration and ensure you meet the requirements.&lt;/li&gt;
&lt;li&gt;Download and install Docker Desktop on Windows.&lt;/li&gt;
&lt;li&gt;Once installed, it should look something like the screenshot shown below. (My Docker version is Version 4.27.2 (137060) at the time of this writing)
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlv9brnb1bdo7biph97o.png" alt="Screenshot of Docker Desktop" width="800" height="110"&gt;
&lt;/li&gt;
&lt;li&gt;With Docker Desktop installed, you can run Docker commands from the Windows Command line.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In this example, I'm going to pull down the Docker MySQL 8.0.36 image by running the following command from the Windows Command Line.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull mysql:8.0.36&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once complete, you can see the image in Docker Desktop when you click on the Images icon on the left as shown here.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk1h53u0081tar4lfhhgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk1h53u0081tar4lfhhgy.png" alt="View Images in Docker Desktop" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next, we will create a container using this image with the command below. The &lt;strong&gt;--name&lt;/strong&gt; is the name of the container, &lt;strong&gt;--env&lt;/strong&gt; used to set the environment variables for the container, &lt;strong&gt;--publish&lt;/strong&gt; is to publish a container's port(s) to the host and finally &lt;strong&gt;--detach&lt;/strong&gt; is to run container in background and print container ID. Please see &lt;a href="https://docs.docker.com/reference/cli/docker/container/run/"&gt;Docker CLI&lt;/a&gt; for more information.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run --name mysql8036-container --env MYSQL_ROOT_HOST=% --env MYSQL_ROOT_PASSWORD=passwordgoeshere --publish 15002:3306 --detach docker.io/library/mysql:8.0.36&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should now see the container named "mysql8036-container" running in Docker Desktop when you click the "Containers" icon on the left.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9j7ff1kbahlojzure6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9j7ff1kbahlojzure6a.png" alt='Docker Desktop showing the container named "mysql8036-container"' width="800" height="60"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next we will connect to this new MySQL instance using MySQL Workbench.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open MySQL Workbench, go to menu option Database - Manage Connections. Click "New". (My version is MySQL Workbench 8.0 Version 8.0.33 build 2947366 CE)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the following information.&lt;br&gt;
a. Connection Name = MySQL8036-Docker&lt;br&gt;
b. Connection Method = Standard (TCP/IP)&lt;br&gt;
c. Hostname = localhost&lt;br&gt;
d. Port = 15002 (The published port from the Docker run command)&lt;br&gt;
e. Username = root&lt;br&gt;
f. Password = passwordgoeshere (The value passed to MYSQL_ROOT_PASSWORD in the run Docker run command)&lt;br&gt;
g. Then click the "Test Connection" to verify connectivity.    &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In MySQL Workbench, use the menu option Database - Connect to Database and the connection we created above to connect to the new database instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the SQL script from above and voila we now have the database and table names with casing as intended.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynf2zqnurzsz1yns8u8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynf2zqnurzsz1yns8u8t.png" alt="MySQL Workbench showing database and table names with intended casing" width="167" height="67"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can now write web/console applications that connect to this instance and not have to worry about case-sensitivity with database and table names. &lt;/p&gt;

&lt;p&gt;I hope this helps you out. Feedback is always welcome.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.docker.com/desktop/install/windows-install/"&gt;https://docs.docker.com/desktop/install/windows-install/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/linux-installation-docker.html"&gt;https://dev.mysql.com/doc/refman/8.0/en/linux-installation-docker.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.docker.com/reference/cli/docker/container/run/"&gt;https://docs.docker.com/reference/cli/docker/container/run/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>docker</category>
      <category>windows</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
