当前位置:网站首页>Docker installing MySQL local remote connection docker container MySQL

Docker installing MySQL local remote connection docker container MySQL

2022-06-13 08:41:00 Python's path to becoming a God

  • install mysql command
sudo docker pull mysql:5.7

 Insert picture description here

  • Set up mysql
sudo docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7

 Insert picture description here
Parameters :

  • -p 3306:3306: The container of 3306 Port mapping to host's 3306 port
  • –name: Name the container
  • -v /mydata/mysql/log:/var/log/mysql: Mount the configuration file to the host /mydata/…
  • -e MYSQL_ROOT_PASSWORD=root: initialization root The user's password is root
    see docker Starting container :
docker ps
  • Set up MySQL Default
cd /mydata/mysql/conf
vi my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

# Esc
# :wq
  • restart MySQL
docker restart mysql
  • Next Empowerment
    Into the container
docker exec -it mysql bash
  • Connect MySQL
mysql -uroot -p root
  • Use mysql
use mysql;
  • Empowerment
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

GRANT: Empowering orders
ALL PRIVILEGES: All permissions of the current user
ON: Preposition
.: The corresponding operation permissions of the current user on all databases and tables
TO: Preposition
‘root’@’%’: Authority is given to root user , all ip Can be connected
IDENTIFIED BY ‘root’: Enter password when connecting , The password for root
WITH GRANT OPTION: Allow cascading weighting

  • Refresh the permissions
FLUSH PRIVILEGES;

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270537577101.html