docker安装mysql遇到的问题

1、docker下载镜像。

#我们查看一下docker.hup上的镜像。
[root@bfd-v7 ~]# docker search mysql
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relation…   5578                [OK]                
mariadb                                                MariaDB is a community-developed fork of MyS…   1728                [OK]                
mysql/mysql-server                                     Optimized MySQL Server Docker images. Create…   383                                     [OK]
hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          77                                      
zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       72                                      [OK]
centurylink/mysql                                      Image containing mysql. Optimized to be link…   58                                      [OK]
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   40                                      [OK]
tutum/mysql                                            Base docker image to run a MySQL database se…   30                                      
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          24                                      [OK]
mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. Cr…   18                                      
schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic backup…   16                                      [OK]
centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   16                                      
linuxserver/mysql                                      A Mysql container, brought to you by LinuxSe…   13                                      
bitnami/mysql                                          Bitnami MySQL Docker Image                      11                                      [OK]
zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        10                                      [OK]
openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 image…   6                                       
centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   6                                       
dsteinkopf/backup-all-mysql       

2、创建mysql的镜像,并运行。

[root@zhaokejin ~]# docker run -p 3308:3306 --name mysql01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
3b42e6847b993d0bafdd8226cfccd33d14ac3eb88c5bbe7171b0a8efebfd592f
[root@zhaokejin ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
3b42e6847b99        mysql               "docker-entrypoint..."   8 seconds ago       Up 7 seconds        0.0.0.0:3308->3306/tcp   mysql01

启动之后我们查看logs;

[root@zhaokejin ~]# docker logs mysql01
Initializing database
2018-05-27T05:58:29.587048Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-05-27T05:58:29.587174Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server in progress as process 26
mbind: Operation not permitted
2018-05-27T05:58:33.015433Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2018-05-27T05:58:33.816724Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816796Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816814Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816841Z 5 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816872Z 5 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816889Z 5 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.816906Z 5 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.817065Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:33.817093Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:34.612656Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server has completed
Database initialized
MySQL init process in progress...
2018-05-27T05:58:36.895768Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-05-27T05:58:36.895903Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 77
mbind: Operation not permitted
2018-05-27T05:58:37.435362Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-05-27T05:58:37.438563Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2018-05-27T05:58:37.447420Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447471Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447482Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447492Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447518Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447528Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.447542Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.450964Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.450984Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:37.457154Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2018-05-27T05:58:39.993692Z 10 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993728Z 10 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993738Z 10 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993748Z 10 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993768Z 10 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993779Z 10 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993793Z 10 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993930Z 10 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:39.993939Z 10 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:42.106960Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.
MySQL init process done. Ready for start up.
2018-05-27T05:58:42.504799Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-05-27T05:58:42.504931Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 1
mbind: Operation not permitted
2018-05-27T05:58:42.995657Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-05-27T05:58:42.998818Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2018-05-27T05:58:43.010014Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.010045Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.010056Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.010066Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.011301Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.011318Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.011341Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.015627Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.015652Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-27T05:58:43.021056Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

说明启动成功了;

然后我们进入docker中mysql

#进入mysql的终端:

[root@bfd-v7 ~]# docker exec -it mysql01 mysql -uroot -p123456

或者

# docker exec -ti xxx(容器id) /bin/bash

# mysql -u root -p

3、设置用户配置项

(1) 查看用户信息

mysql> select host,user,plugin,authentication_string from mysql.user;  
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | caching_sha2_password | $A$005$^]RQB}j~t!      .#v)3.UogPRFu8VJA5/GKEbK5edEQlMT5sHw2n72zYJNlIbo3 |
| localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | mysql.session    | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | mysql.sys        | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | root             | caching_sha2_password | $A$005$Y6&q!59^Fmh)@-6TG58J3F5+3I/HI9L|JCadNG+-+d6W+1D_UFW+7MRD7F3 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+

备注:host为 % 表示不限制ip   localhost表示本机使用    plugin非mysql_native_password 则需要修改密码

navicat链接错误;我们继续往下看;


(2)修改用户密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newpassword'; #更新一下用户的密码 root用户密码为newpassword  
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.06 sec)

docker安装mysql遇到的问题_第1张图片

ok了;


你可能感兴趣的:(Docker)