Advertisement
quark_zju

mysql_scripts.sh

Jan 7th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.21 KB | None | 0 0
  1. # quick dump
  2. mysqldump --compact --skip-opt --skip-lock-tables --single-transaction -q "$@" | pv | gzip > dbdump.gz
  3.  
  4. # create user
  5. CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
  6. GRANT ALL PRIVILEGES ON database.* TO 'newuser'@'%';
  7. FLUSH PRIVILEGES;
  8.  
  9. # remove / grant privileges
  10. DELETE FROM mysql.db WHERE user='phabricator';
  11. GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE, DROP, SHOW VIEW ON `phabricator\_%`.* TO 'phabricator'@'%';
  12.  
  13. # remove anonymous users
  14. delete from mysql.user where password='';
  15.  
  16. # change password
  17. SET PASSWORD FOR 'bob'@'%.example.org' = PASSWORD('cleartext password');
  18.  
  19. # raw user edit (in case grant/revoke not working)
  20. select user,host,password from mysql.user;
  21. delete from mysql.user where password = '';
  22.  
  23. # utf8 issues
  24. CREATE DATABASE $db DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  25. ALTER DATABASE $db CHARACTER SET utf8 COLLATE utf8_general_ci;
  26. ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; # migrates old records
  27.  
  28. # reset root password
  29. service mysql stop
  30. mysqld_safe --skip-grant-tables &
  31. mysql --user=root mysql
  32. update user set Password=PASSWORD('new-password') where user='root';
  33. flush privileges;
  34. exit;
  35. pkill mysqld
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement