Skip to content

Instantly share code, notes, and snippets.

@1isten
Created January 5, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1isten/93ae184c0f2946d159f3d896b81fa7e8 to your computer and use it in GitHub Desktop.
Save 1isten/93ae184c0f2946d159f3d896b81fa7e8 to your computer and use it in GitHub Desktop.
fix default (localhost only) user cannot connect via 127.0.0.1

uninstall if necessary

brew services stop mariadb
brew uninstall mariadb
rm -rf /usr/local/var/mysql /usr/local/etc/my.cnf # be sure to backup first

(re)install

brew install mariadb
brew services start mariadb
sudo mysql_secure_installation
sudo mysql -uroot

list default users

select Host, User, Password from mysql.user;

output is something like this:

+-----------+-------------+----------+
| Host      | User        | Password |
+-----------+-------------+----------+
| localhost | mariadb.sys |          |
| localhost | root        |          |
| ...       | ...         | ...      |
+-----------+-------------+----------+

create new user that can login via other host (% is wildcard), like 127.0.0.1

create user 'admin'@'%' identified by '';
grant all privileges on *.* to 'admin'@'%' identified by '' with grant option;

result:

+-----------+-------------+----------+
| Host      | User        | Password |
+-----------+-------------+----------+
| localhost | mariadb.sys |          |
| localhost | root        |          |
| ...       | ...         | ...      |
| %         | admin       |          | 👈
+-----------+-------------+----------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment