阿里Centos安裝mysql

 

最近使用阿里雲服務器安裝mysql遇到的一些問題,在此記錄下。php

安裝mysql首先要在阿里雲服務器設置頁面裏面打開3306對應的端口號。html

在裏面打開對應的端口號開發,也能夠自定義端口號,建立時能夠選擇。阿里雲安全防護級別比較高,若是要遠程訪問mysql服務器,就必須對指定的ip地址進行受權,每一條規則只能設定一個ip號,一樣的服務如mysql想要受權多個ip地址,就須要克隆設置多個ip地址就行。若是不進行端口號受權,遠程訪問是訪問不了的!mysql

下面來介紹下利用docker安裝mysql。這裏就不介紹docker的安裝方法了,你們能夠去菜鳥網學習安裝。linux

進入到服務器,首先輸入docker search mysql查看下當前docker中有的mysql鏡像,用以選擇下載。nginx

 1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker search mysql  2 NAME DESCRIPTION STARS OFFICIAL AUTOMATED  3 mysql MySQL is a widely used, open-source relation… 7213 [OK]  4 mariadb MariaDB is a community-developed fork of MyS… 2311 [OK]  5 mysql/mysql-server Optimized MySQL Server Docker images. Create… 531 [OK]  6 percona Percona Server is a fork of the MySQL relati… 382 [OK]  7 zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 136 [OK]  8 hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 99  9 zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 74 [OK] 10 centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK] 11 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 48 [OK] 12 centos/mysql-57-centos7 MySQL 5.7 SQL database server 39 13 mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 33 14 tutum/mysql Base docker image to run a MySQL database se… 31 15 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 23 [OK] 16 bitnami/mysql Bitnami MySQL Docker Image 19 [OK] 17 linuxserver/mysql A Mysql container, brought to you by LinuxSe… 17 18 zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 16 [OK] 19 centos/mysql-56-centos7 MySQL 5.6 SQL database server 10 20 circleci/mysql MySQL is a widely used, open-source relation… 7 21 openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6 22 dsteinkopf/backup-all-mysql backup all DBs in a mysql server 5 [OK] 23 mysql/mysql-router MySQL Router provides transparent routing be… 5 24 openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openzip… 1 25 cloudposse/mysql Improved `mysql` service with support for `m… 0 [OK] 26 cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0 27 ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                                       [OK]

如上所示,能夠看到各類版本,在這裏咱們選擇mysql 5.7版原本進行安裝。web

從docker拉取mysql鏡像,docker pull mysql:5.7,固然你也能夠選擇5.6版本,只要選擇對應版本號替換就行。sql

1[root@iZwz9a191mdam4di3dozk3Z /]# docker pull mysql:5.7
 1 5.7: Pulling from library/mysql  2 f17d81b4b692: Pull complete  3 c691115e6ae9: Pull complete  4 41544cb19235: Pull complete  5 254d04f5f66d: Pull complete  6 4fe240edfdc9: Pull complete  7 b79c3b745cc6: Pull complete  8 c6ebcbee59b1: Pull complete  9 e9bb65297d95: Pull complete 10 2a7c8492496e: Pull complete 11 6af69434adbe: Pull complete 12 54bc8b20381b: Pull complete 13 Digest: sha256:b56c3109f09a90c045ebe991e085fcaab5008cd6dbb8ab5ad1d6101fc0f87fcf 14 Status: Downloaded newer image for mysql:5.7

 

而後輸入docker images |grep mysql 查看mysql安裝狀況,顯示以下:docker

1 [root@iZwz9a191mdam4di3dozk3Z mysql]# docker images |grep mysql 2 mysql                5.7                 a46c2a2722b9        4 days ago          256MB

建立mysql,輸入docker create -it mysql:5.7安裝mysql,而後輸入docker run --name mysqlserver -e MYSQL_ROOT_PASSWORD=password -d -i -p 3306:3306 mysql:5.7,運行mysql並設置密碼。ubuntu

1 [root@iZwz9a191mdam4di3dozk3Z mysql]# docker create -it mysql:5.7 2 61c7a4d6363defac673461bb842685302dbe894f96c6dee03f2539de4af2a5d6 3 [root@iZwz9a191mdam4di3dozk3Z mysql]# docker run --name mysqlserver -e MYSQL_ROOT_PASSWORD=sgcc -d -i -p 3306:3306 mysql:5.7 4 e061047acf6e99ca72c22743ee727f708c129cdc8c5628c25e59253db4069ba6

 

查看mysql輸入,docker ps,顯示以下:centos

1 [root@iZwz9a191mdam4di3dozk3Z mysql]# docker ps 2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3 e061047acf6e mysql:5.7 "docker-entrypoint.s…" 13 seconds ago Up 12 seconds 0.0.0.0:3306->3306/tcp mysqlserver 4 024c06fcc1e8 morunchang/fastdfs "sh storage.sh" 3 days ago Up 3 days storage 5 3f2da1b259b5        morunchang/fastdfs   "sh tracker.sh"          3 days ago          Up 3 days

而後執行:docker exec -it e061047acf6e /bin/bash

1 [root@iZwz9a191mdam4di3dozk3Z mysql]# docker exec -it e061047acf6e /bin/bash
「e061047acf6e」是上面CONTAINER ID,對應的mysql:5.7的鏡像。
執行以後鏈接mysql,輸入:mysql -h 127.0.0.1 -u root -p
 1 root@e061047acf6e:/# mysql -h 127.0.0.1 -u root -p  2 Enter password:  3 Welcome to the MySQL monitor. Commands end with ; or \g.  4 Your MySQL connection id is 3  5 Server version: 5.6.42 MySQL Community Server (GPL)  6 
 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

輸入密碼以後就能看到鏈接進入了mysql客服端了,就表示一切ok了。外網遠程訪問時就能夠鏈接了。

利用軟件工具遠程鏈接服務器中的mysql,輸入服務器ip以及帳號密碼就好了。至於mysql用戶名受權什麼的,能夠查看相關mysql的文檔。

相關文章
相關標籤/搜索