docker部署mysql

compose运行

db:
  container_name: mysql
  image: mysql:5.7.17
  command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_unicode_ci
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: 123456
  ports:
   - '3307:3306'
  volumes:
   - '/data/docker/volume/mysql/data:/var/lib/mysql'
   - '/data/docker/volume/mysql/logs:/logs'
   - '/data/docker/volume/mysql/conf:/etc/mysql/conf.d'

直接运行

docker run --name mysql-name -d \
-v /data/docker/mysql/data:/var/lib/mysql \
-v /data/docker/mysql/logs:/logs \
-v /data/docker/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
-p '3310:3306' \
mysql:5.7.19 \
--character-set-server utf8 --collation-server utf8_general_ci  #这个必须在后面

配置修改

docker exec -it mysql bash
--修改密码
update user set authentication_string = password('123456') where user = 'root';

-- 修改密码并运行外网访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

开启binlog

[Docker Mysql容器--开启binlog日志 - CSDN博客](https://blog.csdn.net/harris135/article/details/79712750)



docker exec mysql-name bash -c "echo 'log-bin=/var/lib/mysql/mysql-bin' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
docker exec mysql-name bash -c "echo 'server-id=123454' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
docker restart mysql-imei

results matching ""

    No results matching ""