MacOS M1芯片,docker安装mysql

2022/9/10 2:23:28

本文主要是介绍MacOS M1芯片,docker安装mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.拉取镜像

docker pull ibex/debian-mysql-server-5.7:5.7.26

2.创建宿主配置文件目录和数据目录

mkdir -p /Users/liyabin/docker/mysql/conf
mkdir -p /Users/liyabin/docker/mysql/data

3.编辑配置文件

cd conf
vim my.cnf
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

4.启动mysql镜像

docker run -d \
--name mysql_data_conf \
-p 3306:3306 \
--restart always \
--privileged=true \
-e MYSQL_USER="mysql" \
-e MYSQL_PASSWORD="password" \
-e MYSQL_ROOT_PASSWORD="123456" \
-e character-set-server=utf8 \
-e collation-server=utf8_general_ci \
-v /Users/liyabin/docker/mysql/conf/my.cnf:/etc/my.cnf \
-v /Users/liyabin/docker/mysql/data:/var/lib/mysql \
ibex/debian-mysql-server-5.7:5.7.26

 

 5.登录mysql

mysql -u root -p

 

6.查看用户登录权限

select host, user, authentication_string, plugin from mysql.user; 

 

 7.修改root所有客户端均可访问

update mysql.user set host='%' where user ='root';

 

 8.授权root

grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;

 GRANT:赋权命令

ALL PRIVILEGES:当前用户的所有权限
ON:介词
*.*:当前用户对所有数据库和表的相应操作权限
TO:介词
‘root’@’%’:权限赋给root用户,所有ip都能连接
IDENTIFIED BY ‘123456’:连接时输入密码,密码为123456
WITH GRANT OPTION:允许级联赋权

 9.查看用户权限

SHOW GRANTS FOR 'root'@'%';
SHOW GRANTS FOR 'mysql'@'%';

 10.宿主客户端连接测试

 

 

 



这篇关于MacOS M1芯片,docker安装mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程