数据库
首页 > 数据库> > MacOS M1芯片,docker安装mysql

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,server,cnf,M1,conf,mysql,docker,root
来源: https://www.cnblogs.com/fycn01/p/16671322.html