top of page
Search

How to run mysql on docker and connect from remote

Updated: Sep 7, 2023

So I've spent (too much time and got to much errors in the way)

what worked for me in the end is:


mkdir mysql

create docker-compose.yml

version: '3.1'
services:  
  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test_db
    ports:
      - "3342:3306"
    volumes:
      - $HOME/mysql:/mytmp

and run:


sudo docker-compose up


Now create a user in mysql that will enable you to access from remote (not only localhost):


  • Log in to the MySQL server as a user with sufficient privileges to create users, usually the root user (You'll be prompted to enter the root password.).


	
mysql -u root -p 
  • Run the SQL command to create the user.


CREATE USER 'newuser'@'%' IDENTIFIED BY 'newpassword'; 

--Replace newuser with the desired username and newpassword with --the desired password. The % allows the user to connect from any --IP address.

  • Grant privileges to the new user.

    • To grant all privileges on a specific database:




GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'%'; 

  • To grant all privileges on all databases:




GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%';

  • Then to fix the error in dbeaver (public key error..):


  1. On the "Connection settings" screen (main screen) click on "Edit Driver Settings", located at the bottom right

  2. Click on "Connection properties"

  3. Right-click the "User properties" tab area and choose "Add new property"

  4. Add two properties: "useSSL" and "allowPublicKeyRetrieval"

  5. Set their values to "false" and "true" by double-clicking on the "value" column.



base on:

and

https://www.jsnstop.com/blog/post/mysql-public-key-retrieval-is-not-allowed-how-to-fix-dbeaver-mysql-connection-error

ree

 
 
 

Comments


Subscribe Form

©2019 by Big Data. Proudly created with Wix.com

bottom of page