BryanLundeen.blog

MySQL: Beyond Workbench

guy looking at MySQL on computer screen

Intro

Welcome to MySQL, the go-to database management system for many data analysts, particularly in the e-commerce and web analytics sector. In this post, we’ll delve into some practical aspects of using MySQL for those comfortable with terminal commands and looking for ways to integrate it into various workflows, like Jupyter Notebooks. This approach, although not covered in John Pauler’s “Advanced SQL: MySQL for Ecommerce & Web Analytics” course from Maven Analytics, demonstrates the flexibility and adaptability of MySQL to meet specific needs.

Preparing Your MySQL Environment

Before diving into the deep end, let’s ensure our environment is set up for success. Here’s what you need:

  • MySQL Server installed on your machine.
  • Administrative privileges for MySQL.
  • MySQL Workbench or Command-Line Client at your disposal.
  • A clear plan for your database structure.
  • Don’t forget to back up your existing data!

Running SQL Scripts in the Terminal

For terminal enthusiasts like us, here’s how you can run a SQL script. Paul’s course provides a file called “preparing_workbench_vApril2022.sql.” Start by logging into the server in the terminal:

  • Open Git Bash as an admin.
  • Log into MySQL: mysql -u username -p (replace ‘username’ with yours).
  • Source your script: SOURCE [your-path]/adjust_settings.sql;.

Remember, this method is great for those who are more comfortable outside the GUI realm of MySQL Workbench.

Tweaking the ‘my.ini’ File

Sometimes, you need to change MySQL server settings directly. If you don’t save it to your “my.ini” file, then the next time you start the server, it might not keep the changes. Here’s how:

[mysqld]

# Adjust max packet size for large file handling
max_allowed_packet=1073741824

# Set SQL mode for date flexibility and smarter GROUP BY
sql_mode=TRADITIONAL,ALLOW_INVALID_DATES,ONLY_FULL_GROUP_BY

# Extend timeout settings for those long-running queries
connect_timeout=28800
wait_timeout=28800
interactive_timeout=28800

Always remember: with great power comes great responsibility. Make these changes wisely! 😉

Verifying Your Settings

Trust, but verify! Run these commands to ensure your settings are in place:

SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';
SHOW GLOBAL VARIABLES LIKE 'sql_mode';
SHOW GLOBAL VARIABLES LIKE 'connect_timeout';
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';

Sourcing Additional Scripts

Got another script to run? No problem! Just SOURCE it in your MySQL session:

SOURCE [your-path]/create_database.sql;

Checking Your Work

Ran a script and want to see the fruits of your labor? SHOW TABLES; is your friend:

SHOW TABLES;

Conclusion

Whether you’re following a structured course or charting your own path in the vast ocean of data, MySQL offers the flexibility to adapt to your unique workflow. This post is just a glimpse into how you can leverage MySQL in various environments, be it through traditional tools like Workbench or more command-line-oriented approaches.

Happy data wrangling!

Note: This blog post is tailored to data analysts venturing into MySQL, especially in the context of e-commerce and web analytics. It highlights the adaptability of MySQL for various workflows and serves as a demonstration of problem-solving skills, suitable for those seeking to showcase their abilities to potential employers.

By Bryan Lundeen

Bryan is a Data Analyst working in healthcare. He's passionate about data analysis, web development, SharePoint development, Python and C#. He is a graduate of Phoenix University in Healthcare Administration. See more about Bryan at his LinkedIn page https://www.linkedin.com/in/bryanlundeen/.