Trouble Connecting to Database When Using MySQL 8.x

Recently, I created an issue on the WP-CLI’s entity command repository to introduce a wp site generate command to allow for multisite installs to be easily populated for testing purposes.

I decided to set up a local WP-CLI sandbox on my machine (not within a virtual machine) so I can more easily and consistently contribute to the project. There is great documentation detailing how to contribute code to the project in the WP-CLI handbook. I ended up using the wp-cli-dev repo instead, which sets up every package for development.

After I had everything set up, I experienced database connection issues that took me quite a while to figure out. I hope that this will help save someone else time and frustration!

tl;dr (but you totally should read): MySQL 8.0 changed the preferred authentication plugin from mysql_native_password to caching_sha2_password, which PHP does not yet support. Running this command will fix the issue for the wp_cli_test user expected when running the WP-CLI Behat tests.

ALTER USER 'wp_cli_test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password1';

The Problem: More Details

Being on MacOS, I use Homebrew to install various packages on my machine. After installing mysql with Homebrew, creating the required wp_cli_test database and user, and granting that user the needed privileges for that database, I couldn’t get WP-CLI to connect (connecting via command line worked fine).

$ wp core install
Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down.

What made the situation even more weird was that certain database tasks appeared to complete successfully.

$ wp db check
Success: Database checked.
$ wp db optimize
Success: Database optimized.

I worked through the issue with a coworker and they were able to reproduce the issue. We dug deeper and discovered the following error:

ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found

After researching, I found that there are a few other variations of this notice.

Authentication plugin 'caching_sha2_password' is not supported
Warning: mysqli_connect(): The server requested authentication
method unknown to the client [caching_sha2_password]

What’s Happening

In MySQL 8.0, the default authentication plugin was changed from mysql_native_password to caching_sha2_password (on the MySQL server). This is a problem when the client (PHP in this case) is not aware of this change or does not support the new plugin.

When wp core install is called, the WordPress Database API is used. This means that the call is initiated by PHP as the MySQL client. When wp db check is called, the result is a mysqlcheck call directly to the MySQL server, which is aware of and supports the new authentication plugin.

PHP does not seem to have support for the new caching_sha2_password plugin yet. That explains why PHP initiated requests to the database are failing.

The Solution

After some searching and trial and error, I found three solutions that worked.

First Solution

You can change the authentication plugin used on a per-user basis by running this MySQL command:

ALTER USER 'wp_cli_test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password1';

I chose this route because I was only looking to configure one user for running WP-CLI tests and I want to start using the new authentication plugin as soon as it’s supported by PHP. Future connection failures for new users will remind me to check up on this issue.

Second Solution

If you want to fix the issue for all new users, you can edit the server configuration file to use the previous default authentication plugin (mysql_native_password) by default. To do this, you need to add a line to the my.cnf located in /etc/. When testing this solution, I did not have a my.cnf file present. So, I had to create one.

cd /etc
sudo touch my.cnf

Add the following to that file:

default_authentication_plugin=mysql_native_password

Save and exit, and then restart the server.

mysql.server restart

Note: This change will only apply to new users. The authentication plugin for users created after installing or upgrading to MySQL >= 8.0 will remain unchanged. You will need to apply the first solution to each of these users.

Alternative Solution

There is a third option you could take that I do not really recommend. You could uninstall MySQL 8.x and install 5.7.x. Personally, I always try to work using the latest versions of packages and tools. If you want to take this approach, this is the process I found worked best (this is a combination of steps found in a few different locations).

Note: This will remove all MySQL related data. Make sure to back up any databases you need.

ps -ax | grep mysql
mysql.server stop
brew remove mysql
brew cleanup
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm /etc/my.cnf

Check your .bash_profile file for any MySQL related code and restart your computer.

brew doctor
brew update
brew install [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

Open a new terminal window.

mysql.server start

Notes

It’s worth mentioning that all of these should only be a temporary fix and not a long-term or permanent solution. caching_sha2_password was introduced to provide improved security and performance and it should be utilized when possible.

If you want to read more, a complete breakdown of this change can be found in the MySQL 8.0 Reference Guide, and some details about the issue in PHP can be found on this page. I have also opened a PR to add a notice about this on the Pull Requests page in the WP-CLI handbook.

Consuming Knowledge

One thing that I often find myself struggling with is consuming all the knowledge I want to. I consider myself a pretty curious person, and that often results in a long and overwhelming laundry list of things I want to read, listen to, or watch.

There is just. so. much. to. consume.

Podcasts. YouTube videos. Documentaries. Books. Articles. Documentation. The list goes on.

Previously when I worked at Boston University, I had a pretty long commute (somewhere between 2.5-4 hours a day). I always used that time to listen to the podcasts in my queue But, now that I work remotely, I have “lost” the time (I know, I have technically reclaimed it) that was specifically reserved for consuming the knowledge in those podcasts.

Adding to the difficulty that is the number of topics that pique my interest is the time required for each. For example, some podcasts I enjoy are sometimes as long as 2 or 3 hours. Making time to listen to those regularly while still having time for other things on the list is difficult.

What Does Not Work For Me

I am always thinking about ways to adjust my routine to be better at chunking away at that list and I’m interested in how others accomplish this. Here are some things I have tried and some things that don’t work for me:

  • Unfortunately, I’m not someone that can listen to a deep, thought-provoking conversation while I’m coding or writing. Music is pretty much a requirement for me when working (background noise like at a coffee shop or silence also works). When I am doing administrative tasks, this sometimes works.
  • I have also tried listening to podcasts while walking my dog in the morning. But I find that taking in the sounds of the outdoors is more enjoyable for me during that time.
  • I used to keep one browser window open where I would accumulate tabs for articles I want to read. I never read them with this method. I have moved this list into a “Reading List” list in my personal Trello board. This also seems to result in ignoring them.

To try and prioritize for myself, I have thought about what I currently consume and roughly organized them into three categories. Though some of these will not fit everyone’s tastes, I do recommend them all!

Things I Always Keep Up With

Below is a list of things that I find myself consistently keeping up with accompanied by a reason why I think I am able to keep up with them in paranthases.

Things I Occasionally Keep Up With

Below is a list of things that I find myself occasionally keeping up with accompanied by a short description of what occasionally means for each.

  • The Joe Rogan Experience (2-4 hour episodes make it difficult to listen to all of them. I pick and choose the guests/topics I am curious about, but sometimes struggle to even keep up with those)
  • Crimetown (catch up with binge listening when seasons are finished)
  • Monday Morning Podcast (catch up occasionally with binge listening)
  • More Perfect (catch up by binging)
  • NPR Politics Podcast (pick and choose when to listen when I want to learn more about specific current events)

Things I Want to Get To

These are things I really want to get to, but just have not been able to.

Improving Knowledge Consumption

Where do you find time to consume the information you want to? What are your routines and habits that help with this? And, even though this will add to my long list longer, what are your recommendations? 😄

Featured image by Rosario Lizana.

WordCamp Orlando 2018

Today I gave a talk at WordCamp Orlando titled “Building A Code Review Culture”. Below you can find my slides. I also wanted to share some links for further reading on the topic.

The Guten-Report: WordCamp Portland, ME 2018

Today was WordCamp Portland, ME. There were around 150 attendees that attended this one day WordCamp, and was packed with great sessions.

One time slot was occupied by a panel discussion about Gutenberg where the panel fielded questions from the crowd about the new editing experience. The attendees at this camp represented a good mix of the different types of WordPress users. Attendees were also able to anonymously submit their questions.

I thought this was a great opportunity to take the pulse of the WordPress community.

The panel was moderated by Sam Hotchkiss. These following people were on the panel:

Below is every question that was asked during this session.

  • When you are talking to your clients, do you tell them about Gutenberg, and what you are going to need to do?
  • What do you think the biggest hurdles to adoption are going to be?
  • How comfortable or uncomfortable are you with the short release timeline? How is this affecting your rollout plans?
  • After the introduction, is there a certain overall timeline for adding functionality? Are you talking years? Or less?
  • Gutenberg pushes itself to the top of the page. Is there a way currently, or do you see a way to push this down and add tabs at the top of the screen?
  • How do you see Gutenberg affecting current page builders?
  • Do you see the future of Gutenberg as a full featured drag and drop theme builder?
  • After 5.0, how long do you think that the Classic Editor plugin will be supported?
  • Can you just not update to WordPress 5.0 and keep running the 4.9 branch of WordPress indefinitely?
  • How concerned are you about the lack of parity between Gutenberg and the Classic Editor?
  • What are the pieces you are the most nervous about with Gutenberg rolling out?
  • What are the pieces you are the most excited about with Gutenberg rolling out?
  • What is the current state of Gutenberg in mobile?
  • What resources would you recommend to someone that wants to get started in Gutenberg development?

Accessibility: A Developer’s Pledge

My grandfather was legally blind.

Even in my earliest memories of him, he did not drive, My grandmother drove until she needed to give up driving herself. He never really described his vision to me in detail, but I do remember him saying it was darker, he saw mostly shapes and outlines, and he always asked you to move in closer when having a conversation so he could see you. He carried his folding white cane everywhere with him (if you see someone with a white cane, offer assistance), and we always looked after him to make sure he had everything he needed to be independent and live on his own.

He suffered from Macular Degeneration, an incurable eye disease that causes degradation of vision, straight lines to appear wavy, and dark or blurry areas in the center of your vision.

Macular degeneration is the leading cause of vision loss, affecting more than 10 million Americans – more than cataracts and glaucoma combined.

(source: American Macular Degeneration Foundation)

He was a very proud veteran, serving for the US Navy during the Korean War aboard the USS Allen M. Sumner (DD-692). He fondly told stories of his time at sea circumnavigating the globe, having stopped in Spain, Greece, Japan, and more (if this interests you, you can read the ship’s entire 1953 log book, or view information about the ship’s Korean War deployment). He was honorably discharged on May 19th, 1955 as a MM2 (Machinist Mate Second Class) and returned home.

A photo of Harold Jackson on the USS Allen M. Sumner with bedding draped over the railings.
My grandfather on “air bedding” day (days when bedding was tied to life lines to air out)

Many years later when his vision had declined, his veteran status made him eligible for computer training in Connecticut. While there, he and other blind veterans were taught how to use the computer to perform general tasks, everything from composing documents and printing to sending e-mails and using the Internet. After his training, he returned home and a technician came to his house to set up a computer for him to use.

We emailed back and forth regularly, which was great! I still have some of them in an old email account of mine, asking for scuttlebutt for the “ol’ sea dog”. When I visited him, he was always excited to show me the new projects he was working on, the new useful site he had discovered, or the new tricks he had learned. Since I was good with computers (and his grandson), he also turned to me for help.

Because he was blind, he relied on a combination of screen reading software (JAWS) and zoom software to magnify his screen to a size that he could read. Using a screen reader takes a lot of patience. At first, helping him was difficult for me. I had to slow down considerably in order to allow him time to listen and step through the commands and navigate the screen with JAWS. Eventually, I adjusted, and I frequently helped him with common issues he experienced.

What’s The Point?

While I enjoy reminiscing about the times I shared with my grandfather, I am telling you about him for a reason. My experiences with my grandfather made me aware of accessibility and its importance, specifically related to blindness. Some people are never exposed to anyone with a disability, so I consider myself to have an above average awareness of accessibility.

When I think of accessibility, I think of my grandfather. I watched the Internet open so many doors for him. He had a new hobby to pass the time. He scanned old photograph slides and photos and shared them with family and friends who had no idea they existed. He reconnected with old shipmates and contributed his photos and stories to the officially commissioned website for his destroyer. He helped produce and edit email newsletters for online blind communities.

While at a Blind Veterans of America (BVA) reunion in 2006, a former ship mate (who was not blind) decided to drive the 2 hours to the reunion to surprise him. He knew my grandfather would be there after reconnecting through email. The two had not seen each other in over 54 years.

A newsletter clipping about my grandfather reuniting with an old friend after 54 years.
A newsletter clipping my grandfather shared with his destroyer’s website.

I want WordPress to open the same doors for everyone, regardless of their mental or physical abilities.

When I worked at Boston University, I frequently asked team members to revise designs or update markup to be more accessible. I played around with pa11y and proposed adding an automated accessibility scan to our pull request process. When I have questions about accessibility best practices, I reach out to accessibility contributors for answers.

But, up until now, my involvement with accessibility has only met the bare minimum. And I want to do better.

Fixing The Problem

This post is not to discuss why certain decisions have been made, the politics of those decisions, or the different opinions of whether Gutenberg is the right thing for WordPress (for the record, I believe it is). What’s done is done, and I’m not aware of any time machines in existence.

This is a personal exercise for me to take my share of the responsibility for the current state of accessibility, and define the steps I am going to take to improve it.

The problem: I have not done enough to positively progress accessibility in WordPress.

Accessibility is not just about physical disabilities, whether permanent such as blindness or temporary due to a broken arm. Accessibility can also help those with cognitive disabilities, such as Dylexia. It even benefits those without disabilities dealing with situational limitations, such as being in bright sunlight, or living in an area with expensive or low bandwidth.

The passionate WordPress accessibility community needs support. Many are burnt out, beyond frustrated. They have been asking, hell, pleading with us to do more to progress accessibility. More people need to join in and help. It’s time for more people to listen.

My Pledge

Below is what I am pledging to do moving forward:

  • I pledge to learn something new about accessibility every week.
  • I pledge to blog about what I learn to help spread awareness and share knowledge.
  • I pledge to provide closed captions for any publicly available video of me speaking.
  • I pledge to spend two days a month working exclusively on accessibility tickets for WordPress (I will still work on accessibility tickets outside of these two days, but these days will exclusively be accessibility).
  • I pledge to more closely follow the #accessibility meetings in the WordPress.org Slack and offer help whenever I can.

In the grand scheme of things, this is not a lot at all. But, if everyone makes a similar pledge to do something to progress accessibility, it will quickly add up.

I challenge everyone to step back and think about what they have done recently to progress accessibility in WordPress, and consider why they have not done more.

Please, hold me accountable to my pledge above. Ask me which days I focused on accessibility tickets this month. Ask me what I have learned this week about accessibility. Ask me for a ticket you can help out on.

Write a blog post with your own reflection and pledge. Comment below with your pledge. Put it somewhere publicly and ask your peers to hold you accountable.

A photo of Harold Jackson Sr..
Harold Jackson Sr. – 1932-2011

Note:

I am extremely fortunate to be part of a team at Bluehost that is sponsored to contribute to the WordPress open source project. Part of my job (as I see it) is community service.

I am always available to anyone who needs help with any aspect of contributing to WordPress. Anything from help with running VVV to writing a component meeting summary. You are always welcome to ping me and ask for help on Slack.

I’m Blue: My Next Chapter

Today is my last day at Boston University, a place that I have worked at for nearly two years. I am extremely excited to start my new full-time job on Monday as a WordPress Core Contributor at Bluehost.

Contributing to WordPress is very important to me. I believe in what WordPress represents and the doors that it opens for millions of people. I am excited that I can now focus entirely on contributing to and making WordPress better.

As I reflect on my time at Boston University, there are things I won’t miss about working here (*cough* traffic *cough*), but there are many more things that I will miss. My department, Interactive Design, and the University as a whole is full of amazing and inspiring people. If you are in the Boston area and are looking for work, I highly recommend that you reach out.

I was encouraged to grow by attending conferences, including being sent to Paris in 2017 to attend the WordPress Community Summit (one of my proudest professional moments) & WordCamp Europe.

I think about some of the projects I had a hand in:

  • Questrom School of Business
  • College of Arts & Sciences
  • Of Hoops & Healing (Winter-Spring 17 Bostonia feature)
  • I helped re-engineer the internal (soon to be open sourced) theme framework that runs a large percentage of BU websites to make it easier to build on.
  • I helped implement a pull request/peer review workflow that included coding standards checks using CodeClimate.
  • Created a banner plugin called BU Banners that will be activated on every new site moving forward (also soon to be open sourced).

And these are just the things that come to mind as I write this.

After today, the scarlet will fade to blue, but I’ll always be thankful for my time and experiences at BU. ♥️

WordPress Boston – March

Last night, I gave a short talk at the monthly Boston WordPress meetup about what plugins I use. Below is the list, in case you wanted to look into them and try them out.

And finally, my absolute favorite, must have plugin.

Query Monitor – John Blackbourn

What are your favorites? Comment below!

WordCamp RI 2017

Today, I will be giving a talk at WordCamp Rhode Island. Even though I am an organizer for WordCamp Boston and the WordPress Boston meetups, I have always considered WordCamp Rhode Island as my home WordCamp. I have spoken every year since its inception (previously WordCamp Providence).

This year, my talk is titled “Coding Standards: What They Are and Why You Should Follow Them”.

Slides

You can follow along during my talk with my slide deck if you would like.

Slide Deck

Below, is a list of links to things mentioned in my talk.

WordPress Coding Standards
WordPress Core Trac Tickets
Code Linting Resources
Services

Space Exploration is Awesome

Space exploration has always been fascinating to me, both manned and unmanned. There is something about the unknown vastness of space that provokes endearing curiosity. The Cassini-Huygens project has fed that curiosity for years, but will stop doing so later this week.

The New York Times posted a great article last week detailing the impending demise of the Cassini-Huygens spacecraft, an unmanned space probe that has been pestering Saturn and its moons over the last 13 years. While the Huygens part of the craft (a probe designed to separate and land on Titan, one of Saturn’s moons) has been dead since 2005, the Cassini part of the craft has been weaving in and out of Saturn’s rings and moons collecting data, photos, and even sounds for over a decade.

So Long. Farewell

On Friday, September 15th at approximately 7:53am EDT, Cassini will descend towards Saturn where it will transmit its last messages and disintegrate into the atmosphere. The article’s video does a great job of detailing the whole project and illustrating the final descent of the elder spacecraft.

Rest in peace.

Be sure to check out the original article.

%d bloggers like this: