MYSQL docker鏡像簡單安裝數據庫

獲取mysql的鏡像
docker search mysql

[root@tanli ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relati...   8765      [OK]       
mariadb                           MariaDB is a community-developed fork of M...   3074      [OK]       
mysql/mysql-server                Optimized MySQL Server Docker images. Crea...   650                  [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   64                   
centurylink/mysql                 Image containing mysql. Optimized to be li...   61                   [OK]
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. ...   55                   
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com...   41                   [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      35                   [OK]
tutum/mysql                       Base docker image to run a MySQL database ...   34                   
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic back...   28                   [OK]
prom/mysqld-exporter                                                              23                   [OK]
linuxserver/mysql                 A Mysql container, brought to you by Linux...   22                   
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   16                   
circleci/mysql                    MySQL is a widely used, open-source relati...   15                   
mysql/mysql-router                MySQL Router provides transparent routing ...   13                   
arey/mysql-client                 Run a MySQL client from a docker container      12                   [OK]
imega/mysql-client                Size: 36 MB, alpine:3.5, Mysql client: 10....   8                    [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 ima...   6                    
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron t...   4                    [OK]
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                    [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  2                    [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offi...   2                    
jelastic/mysql                    An image of the MySQL database server main...   1                    
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Cu...   0                    [OK]
monasca/mysql-init                A minimal decoupled init container for mysql    0                    

把鏡像mysql 5.6版本的拉下來
docker pull mysql:5.6

查看images裏面的是否已經存在mysql
docker images |grep mysql

[root@tanli ~]# docker images |grep mysql
mysql                        latest              c7109f74d339        4 months ago        443MB
mysql                        5.6                 27e29668a08a        10 months ago       256MB

鏡像搞定這樣就可以直接去啓動一個容器
docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v
$PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

命令說明:

-p 3306:3306:將容器的 3306 端口映射到主機的 3306 端口。
-v -v $PWD/conf:/etc/mysql/conf.d:將主機當前目錄下的 conf/my.cnf 掛載到容器的 /etc/mysql/my.cnf。
-v $PWD/logs:/logs:將主機當前目錄下的 logs 目錄掛載到容器的 /logs。
-v $PWD/data:/var/lib/mysql :將主機當前目錄下的data目錄掛載到容器的 /var/lib/mysql 。
-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用戶的密碼。

docker ps

[root@tanli ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
76360d62e6ef        mysql:5.6           "docker-entrypoint..."   16 hours ago        Up 16 hours         0.0.0.0:3306->3306/tcp   mysql

進入docker 容器中的命令 exec -it
docker exec -it 容器ID /bin/bash

進入docker編輯mysql模式
docker exec -it mysql mysql -uroot -p123456

[root@tanli ~]# docker exec -it mysql  mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 57
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

處理用戶的能否遠程創建數據庫
select host,user,plugin,authentication_string from mysql.user;

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

修改root權限幾種方法

#登錄mysql
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xiaoxiang123';

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY  1234567;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;



alter user 'root'@'%' identified by '123456';

delete from user where  host='localhost';

flush privileges;

創建數據庫基本語法

CREATE USER 'xiaoxiang'@'%' IDENTIFIED WITH mysql_native_password BY 'xiaoxiang123!';
GRANT ALL PRIVILEGES ON *.* TO 'xiaoxiang'@'%';

CREATE DATABASE xiaoxiang123;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章