Guest User

Untitled

a guest
Nov 29th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. ## Mysql
  2. Create the directory
  3. ```bash
  4. mkdir -p ~/.dockerdata/mysql/my.cnf.d/
  5. ```
  6.  
  7. Create a file with to set a custom mysql configuration
  8.  
  9. ```
  10. touch ~/.dockerdata/mysql/my.cnf.d/custom.cnf
  11. ```
  12.  
  13. Write the configuration bellow:
  14.  
  15. ```
  16. [client]
  17. default-character-set=utf8
  18.  
  19. [mysql]
  20. default-character-set=utf8
  21.  
  22. [mysqld]
  23. collation-server = utf8_unicode_ci
  24. character-set-server = utf8
  25. default_authentication_plugin = mysql_native_password
  26. ```
  27.  
  28. Create Mysql container
  29.  
  30. ```
  31. docker run --name mysql -v ~/.dockerdata/mysql/my.cnf.d/:/etc/my.cnf.d -e MYSQL_ROOT_PASSWORD="root" -p 3306:3306 -d mysql/mysql-server:5.7
  32. ```
  33.  
  34. Access mysql container bash
  35.  
  36. ```
  37. docker exec -it mysql bash
  38. ```
  39.  
  40. Grant ownership to mysql user
  41. ```
  42. chown -R mysql:mysql /var/lib/mysql
  43. ```
  44.  
  45. Access mysql from container, update hosts and grant all privileges to root;
  46.  
  47. ```
  48. mysql -uroot -proot
  49. UPDATE user SET Host='%' WHERE User='root';
  50. GRANT ALL PRIVILEGES ON *.* TO root@'%' WITH GRANT OPTION;
  51. FLUSH PRIVILEGES;
  52. ```
  53.  
  54. Restart mysql container
  55.  
  56. ```
  57. docker restart mysql
  58. # or
  59. docker stop mysql; docker start mysql;
  60. ```
Add Comment
Please, Sign In to add comment