Mac m1 Ubuntu里docker中安装mysql

天下之事常成于困约,而败于奢靡。这篇文章主要讲述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 m1 Ubuntu里docker中安装mysql

文章图片

3、查看镜像
Mac m1 Ubuntu里docker中安装mysql

文章图片

4、启动镜像登录mysql
Mac m1 Ubuntu里docker中安装mysql

文章图片

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: 1Changed: 1Warnings: 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: 1Changed: 1Warnings: 0

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

6、宿主机连接
Mac m1 Ubuntu里docker中安装mysql

文章图片



7、mac用datagrip连接
Mac m1 Ubuntu里docker中安装mysql

文章图片



【Mac m1 Ubuntu里docker中安装mysql】
Mac m1 Ubuntu里docker中安装mysql

文章图片


    推荐阅读