Last active
April 17, 2019 03:44
-
-
Save bot11/b8f82630e61f65cc54656bb422f2463f to your computer and use it in GitHub Desktop.
MySQL mariadb run a test container on your machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Pull docker image | |
$ docker pull mysql:5.7 | |
2) Generate mysql random password for rot user. | |
$ export MYSQL_ROOT_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | sed 1q) | |
3) create the container. | |
$ docker run -d --name mysql -p 3306:3306 --env MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} docker.io/mysql:5.7 | |
4) Connect to the container to change the password and create new user if you want to connect from the host. | |
From host to connect to the container the traffic goes from the gateway (which we can get from docker inspect). | |
Use this IP while creating the user. | |
$ docker exec -it 6fa4b4071092 /bin/bash | |
root@6fa4b4071092:/# mysql -u root -p | |
Enter password: | |
Welcome to the MySQL monitor. Commands end with ; or \g. | |
Your MySQL connection id is 5 | |
Server version: 5.7.25 MySQL Community Server (GPL) | |
reference: | |
https://severalnines.com/blog/mysql-docker-containers-understanding-basics | |
https://coreos.com/quay-enterprise/docs/latest/mysql-container.html | |
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. | |
Oracle is a registered trademark of Oracle Corporation and/or its | |
affiliates. Other names may be trademarks of their respective | |
owners. | |
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. | |
mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Abc.1234'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> create user 'root'@'172.17.0.1' identified by 'Abc.1234'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> GRANT ALL PRIVILEGES ON * . * TO 'root'@'172.17.0.1'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> exit | |
Bye | |
root@6fa4b4071092:/# exit | |
Common issues to debug: | |
$ perl d.pl | |
install_driver(mysql) failed: Can't load '/usr/lib64/perl5/vendor_perl/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.18: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 190. | |
at (eval 9) line 3. | |
Compilation failed in require at (eval 9) line 3. | |
Perhaps a required shared library or dll isn't installed where expected | |
at d.pl line 57. | |
$ find /usr/lib64/ -name libmysqlclient.so.18 | |
/usr/lib64/mysql-workbench/libmysqlclient.so.18 | |
[deepak@rbattu bin]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH}:/usr/lib64/mysql-workbench | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment