Josheli
  • Home
  • Blog
    • Knob
    • Running
    • Soccer
    • Technology
  • About
Knob , Technology

MariaDB or MySQL Root Password Struggles on Debian/Ubuntu

by dv March 14, 2018 1 Comment

Had a difficult time authenticating to a newly installed MariaDB 10.1 instance on Debian 9 (Stretch) recently, wasting a couple of hours and some precious late-night sanity, so I wanted to document that here for myself later, and anyone else who might run across this.

As part of a learning exercise I wanted to install a PHP web app on the cloud somewhere, so I chose Google Cloud Platform using their “always free tier”, which includes free, tiny f1-micro instances. Process was pretty easy, and using their LAMP quick start I created a new LAMP Virtual Machine with Debian Stretch. All was pretty easy except for the MySQL installation.

This step in particular was a crap-fest:
sudo mysql_secure_installation

During this step you’re supposed to set the root password for MySQL/MariaDB, but it doesn’t actually work. I spent an hour uninstalling and reinstalling MariaDB, then re-running that step with no luck. A random mailing list from the Debian forums mentioned that “mysql_secure_installation” doesn’t really work anymore. Then, this answer on Ubuntu forums pointed me to this blog post from Percona that explains the problem pretty well.

Basically, by default MySQL 5.7/MariaDB 10.1 don’t allow root login with a password. They don’t even let you set a password. By default, you’re supposed to log in using sudo:

So this works:
sudo mysql -u root

But this doesn’t:
sudo mysql -u root -p my-password

Meanwhile, you don’t know that because when you run the mysql_secure_installation script that every tutorial tells you to run, it asks you to set a root password. But that doesn’t do anything, and doesn’t work, so you’re in this loop of not being able to log in.

Anyway, the solution in the Percona blog (to change this default “no-password login” behavior back to allowing a password login) didn’t work either, until I read one of the comments.

In particular, this didn’t work for me:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';

But this did:
UPDATE mysql.user SET authentication_string = PASSWORD('test'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

And now you can log in to MySQL or MariaDB as root with a password:
mysql -u root -p

Oh, installing phpMyAdmin from an apt package didn’t work for some reason either, but I ignored that and used the command line.

Anyway, it all sucked for a night, so I hope someone else (me?!) finds my pain useful later.

Related Content:

  • Continuous Deployment: Drupal 8, Composer, Github,… by Dv April 17, 2018 UPDATE: Watch a tech talk I recently gave at work about this process. I've been doing some pretty cool work…
  • Install Ubuntu on HP Laptop with UEFI and new SSD Hard Drive by Dv November 22, 2016 It shouldn't be this hard. I must have installed and re-installed Ubuntu 16.04 twenty times before I found the magic…
  • A New, Old Hobby: Self-hosted Services by Dv February 21, 2021 I've recently returned to a hobby of mine ... self-hosting various software services and web applications on a server I…
  • Dockerizing PHP apps and deploying to AWS Fargate Part 1 by Dv February 6, 2019 For the day job, I maintain four custom PHP apps in addition to several Drupal sites. Up until a couples…
  • Setting up WordPress to use SSH for Updates by Dv December 18, 2015 Here's how I set up WordPress to seamlessly use SSH, rather than FTP, for updates. Using this method, I never…
It's only fair to share...Share on facebook
Facebook
Share on twitter
Twitter
Share on email
Email
  • Previous Lafayette Oatmeal Festival 5K: It’s the Right Thing To Do7 years ago
  • Next Continuous Deployment: Drupal 8, Composer, Github, Pantheon and CircleCI7 years ago

comments title

  1. os advocate says:
    August 28, 2018 at 3:52 pm

    So I just installed MariaDB 10.1 on Ubuntu 18.04 and I didn’t run into this problem. mysql_secure_installation seemed to work as intended. Maybe it’s a Debian only thing? Or it’s resolved?

Leave a Reply

Your email address will not be published. Required fields are marked *

Popular Posts

  • Josheli, What Happened? (55,009)
  • Stupidly Simple, Static, Startpage for Self-hosted Services (29,606)
  • Running a Plex Media Server on an Old Laptop (25,802)
  • Simple Google Photos: A WordPress Plugin (22,731)
  • Only Say True Things (22,075)

Random Read

I'll be fine
So I'm thinking about signing up for the marathon and switching to the Monday/Wednesday morning…

Read More

Google Photo
Google Photo
Google Photo
Google Photo

Social Things

  • Family Vance
  • Texas Longhorns News

RSS From Familyvance

  • Snowshoeing at Brainard Lake
  • Fishing and Hiking at Golden Gate Canyon State Park
  • Rainbow Trout Fishing Report at Waneka Lake
  • Weightless Texas-Rig Plastic Worms at Sawhill Ponds and Coot Lake
  • Sawhill Ponds Fishing Report
2025 Josheli. Donna Theme powered by WordPress