mac系統下docker 安裝mysql8

https://www.cnblogs.com/badtree/articles/10130695.html

https://www.linuxidc.com/Linux/2019-02/157029.htm

 

1、~ docker pull mysql:8

➜  ~ docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
mysql                             8                   c8ee894bd2bd        12 days ago         456MB
redis                             latest              598a6f110d01        3 months ago        118MB
mysql                             5.7                 a1aa4f76fab9        4 months ago        373MB

2、從鏡像啓動一個容器

~ docker run -p 3306:3306 --name mysql8 \
-v /Volumes/data/develop/mysql/8/logs:/var/log/mysql \
-v /Volumes/data/develop/mysql/8/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=password \
-e TZ='Asia/Shanghai' \
--restart=always \
-d mysql:8 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_general_ci

注意:可以直接啓動容器的時候直接映射配置文件,添加如下的腳本,注意路徑和文件名即可;

-v /Volumes/data/develop/mysql/8/conf/my.cnf:/etc/mysql/my.cnf:rw \

配置文件基本的內容如下:(最後六行是自己配置的,其餘都是從容器中拷貝的)

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/

 

character-set-server=utf8

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

 

➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
54fd46e1e8f8        mysql:8             "docker-entrypoint.s…"   28 seconds ago      Up 27 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql8

3、 進入docker的mysql容器
➜  ~ docker exec -it mysql8 /bin/bash

root@54fd46e1e8f8:/#

4、登錄數據庫(此處的密碼爲參數-e MYSQL_ROOT_PASSWORD=password對應的值,此處密碼爲password)
        #  mysql -uroot -ppassword
root@54fd46e1e8f8:/# mysql -uroot -ppassword
mysql: [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 8
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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.

本機使用的話,此處已經OK了,

5、使用mysql數據庫
mysql> use mysql;

6、mysql8.0的root用戶的驗證方式變了,通過查詢:select host,user,plugin from user;

mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

得知:root的用戶的加密方式爲caching_sha2_passoword, 而navicat老版本(新版本不需要修改)連接所用的方式爲native_password。mysql爲遠程連接和本地連接提供了不同的密碼驗證方式。

修改root用戶插件驗證方式:

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

賦權限:

mysql> alter user 'root'@'localhost' identified by 'password';

mysql> alter user 'root'@'%' identified by 'password';

刷新權限:

mysql> flush privileges;

 

可以查看mysql的字符編碼

mysql> show variables like'character%';

 

 

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