Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/bin/bash -ex
  2.  
  3. # If you thought you installed MySQL and got MariaDB instead, you might have difficulty creating the first user
  4. # and logging in. There might be a root user that uses integrated authentication with the linux root account,
  5. # and MariaDB seems to have a different syntax than MySQL for creating users.
  6. # If so, this script uses the root account to create another user with a traditional password and full rights.
  7. # After that, mysql-workbench should work as expected with the new local account.
  8.  
  9. # Tested on a Raspberry Pi running Raspbian GNU/Linux 9 (stretch).
  10.  
  11. alias mysql='mysql --host=localhost --database=mysql';
  12. alias sudo='sudo '; # allows next word to be an alias
  13. shopt -s expand_aliases; # interpret aliases
  14.  
  15. # secret-tool comes from package libsecret-tools, which enables command-line access to the gnome keyring;
  16. # this script stores/retrieves a mysql password in the gnome keyring in the format used by mysql-workbench
  17. if ! password=$(secret-tool lookup account $USER service Mysql@localhost:3306); then
  18. secret-tool store --label=$USER@localhost account $USER service Mysql@localhost:3306;
  19. password=$(secret-tool lookup account $USER service Mysql@localhost:3306);
  20. fi;
  21.  
  22. sudo mysql --execute="
  23. drop user if exists $USER@'%';
  24. drop user if exists $USER@localhost;
  25. create user if not exists $USER@'%' identified by '$password';
  26. grant all privileges on *.* to $USER@'%' with grant option;
  27. ";
  28.  
  29. mysql --user=$USER --password="$password" --execute="
  30. select user, host, password, plugin, authentication_string, password_expired, is_role, default_role
  31. from user;
  32. ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement