先提前说一下,如果你是阿里云服务器,同时你3306端口怎么都访问不到,那你要注意:
查看linux内核,现在最新版本的docker要求内核最低为3.10。由于我的内核版本是3.10,所以下面描述最新版的安装方法。
[root@zhaokw ~]# uname -r
3.10.0-514.26.2.el7.x86_64
sudo yum -y remove docker
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install -y yum-utils
yum install docker -y
systemctl start docker #启动docker
systemctl enable docker #开机启动docker
systemctl status docker #查看docker状态
docker version #查看docker版本
修改/etc/docker/daemon.json文件,内容如下:
{
"registry-mirrors": ["https://hqqnn9fk.mirror.aliyuncs.com"]
}
[root@zhaokw etc]# docker search mysql
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/mysql MySQL is a widely used, open-source relati... 9198 [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 3274 [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 680 [OK]
docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 70
docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 65
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 61 [OK]
docker.io docker.io/deitch/mysql-backup REPLACED! Please use http://hub.docker.com... 41 [OK]
docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 36 [OK]
docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 34
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 29 [OK]
docker.io docker.io/prom/mysqld-exporter 27 [OK]
docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 24
docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 19
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 19
docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 14
docker.io docker.io/arey/mysql-client Run a MySQL client from a docker container 13 [OK]
docker.io docker.io/databack/mysql-backup Back up mysql databases to... anywhere! 10
docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6
docker.io docker.io/fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron t... 5 [OK]
docker.io docker.io/genschsa/mysql-employees MySQL Employee Sample Database 4 [OK]
docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
docker.io docker.io/devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offi... 2
docker.io docker.io/jelastic/mysql An image of the MySQL database server main... 1
docker.io docker.io/monasca/mysql-init A minimal decoupled init container for mysql 0
docker.io docker.io/widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 0 [OK]
docker pull mysql
[root@zhaokw etc]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql latest 9b51d9275906 2 days ago 547 MB
docker run -p 3306:3306 --name mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
docker ps #查看目前工作的容器
docker ps -a #查看所有运行过的容器
Navicat连接linux上的mysql时报如下错误:
错误原因:
从mysql5.7版本之后,默认采用了caching_sha2_password验证方式。
解决办法:
在linux服务器中,开启mysql,并进入连接的数据库执行如下语句,表示采用原来的身份验证机制。
进入容器docker exec -it mysql bash
然后以root身份登录mysqlmysql --user=root --password
输入root的密码(默认为'root')最后运行:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
之后连接就成功了。