Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -ex
- # If you thought you installed MySQL and got MariaDB instead, you might have difficulty creating the first user
- # and logging in. There might be a root user that uses integrated authentication with the linux root account,
- # and MariaDB seems to have a different syntax than MySQL for creating users.
- # If so, this script uses the root account to create another user with a traditional password and full rights.
- # After that, mysql-workbench should work as expected with the new local account.
- # Tested on a Raspberry Pi running Raspbian GNU/Linux 9 (stretch).
- alias mysql='mysql --host=localhost --database=mysql';
- alias sudo='sudo '; # allows next word to be an alias
- shopt -s expand_aliases; # interpret aliases
- # secret-tool comes from package libsecret-tools, which enables command-line access to the gnome keyring;
- # this script stores/retrieves a mysql password in the gnome keyring in the format used by mysql-workbench
- if ! password=$(secret-tool lookup account $USER service Mysql@localhost:3306); then
- secret-tool store --label=$USER@localhost account $USER service Mysql@localhost:3306;
- password=$(secret-tool lookup account $USER service Mysql@localhost:3306);
- fi;
- sudo mysql --execute="
- drop user if exists $USER@'%';
- drop user if exists $USER@localhost;
- create user if not exists $USER@'%' identified by '$password';
- grant all privileges on *.* to $USER@'%' with grant option;
- ";
- mysql --user=$USER --password="$password" --execute="
- select user, host, password, plugin, authentication_string, password_expired, is_role, default_role
- from user;
- ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement