Mac m1 Ubuntu里docker中安装mysql

Posted hyunbar777

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac m1 Ubuntu里docker中安装mysql相关的知识,希望对你有一定的参考价值。

0、环境

  • mac m1
  • 虚拟机pd+Ubuntu(arm64)
  • mysql 5.8

1、问题

m1 直接docker pull mysql 报:

MacBook-Pro ~ % docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
no matching manifest for linux/arm64/v8 in the manifest list entries

Docker Hub上没有适用于arm64架构的mysql镜像。

M1芯片是arm64架构,也称作aarch64架构,只能运行arm64/aarch64架构的程序。

所以ubuntu也是arm64架构,才能装上。

为啥不装centos,因为实在装不上。

2、使用:docker pull mysql/mysql-server:latest

Mac

3、查看镜像

Mac

4、启动镜像登录mysql

Mac

5、配置

5.1 总体配置
 mysql> use mysql;
Database changed
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

mysql> use mysql;
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | healthchecker |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql> update mysql.user set host=% where user=root;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

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

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
5.2 修改密码

mysql5.8前修改密码:

 mysql> UPDATE user SET Password = password ( 123456 ) WHERE User = root;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ( a123456 ) WHERE User = root at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql5.8后修改密码:

查看版本

 bash-4.4# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 166
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> update user set authentication_string=password(123456) where user=root;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

方式二:

 mysql> ALTER USER root@% IDENTIFIED WITH mysql_native_password BY 123456;
Query OK, 0 rows affected (0.01 sec)

6、宿主机连接

Mac


7、mac用datagrip连接

Mac


Mac

以上是关于Mac m1 Ubuntu里docker中安装mysql的主要内容,如果未能解决你的问题,请参考以下文章

mac pro M1(ARM)安装:ubuntu桌面版虚拟机

在Ubuntu中安装Docker和docker的使用

在Ubuntu中安装Docker和docker的使用

如何在docker中安装vsftp

mac下docker中安装nodejs

在Ubuntu中安装Docker