docker - 使用mysql 的docker镜像

访问量: 369

1. 需要在本地创建一个文件夹, 例如  /workspace/mysql_data

2. chmod 777 mysql_data  (非常重要,具体参考:

https://stackoverflow.com/questions/39175194/docker-compose-persistent-data-mysql

这个说的是chown 

https://stackoverflow.com/questions/54507881/docker-compose-mysqld-cant-create-write-to-file-var-lib-mysql-is-writable

)

3. 设置docker-compose.yml  内容如下

version: '3'
services:

  mysql:
    container_name: "mysql-5.7"
    image: mysql:5.7         
    volumes:
      - /home/ubuntu/apps/mysql_data:/var/lib/mysql
    command: 'tail -F /dev/null'
    ports:
      - "3306:3306"
    stdin_open: true
    tty: true
    environment:
      - MYSQL_ROOT_PASSWORD=666666

4. docker-compose up 

5. 进入到mysql docker,  然后修改配置文件, /etc/mysql/mysql.conf.d#

bind_address = 0.0.0.0 

6. 重新创建一个用户

mysql> CREATE USER 'xxx'@'%' IDENTIFIED BY '666666';
Query OK, 0 rows affected (0.05 sec)

mysql> grant all on *.* to 'xxx'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT host, user FROM mysql.user;
+---------+---------------+
| host    | user          |
+---------+---------------+
| %       | xxx     |
| 0.0.0.0 | mysql.session |
| 0.0.0.0 | mysql.sys     |
| 0.0.0.0 | root          |
+---------+---------------+
4 rows in set (0.00 sec)

订阅/RSS Feed

Subscribe