mac上mysql装置与58fair热跟新server本地部署

操作体系版别:macOS 13.4
电脑型号:MacBook Pro 13-inch, M1, 2020
芯片:Apple M1
内存 16G

遇到一个mysql问题

MySQL Client Error: Authentication plugin not supported: caching_sha2_password

记载如下。

mysql 装置

8.0.xx版别

mysql官方下载地址:downloads.mysql.com/archives/co…

这儿选择 点击下载macOS 13 (ARM, 64-bit), DMG Archive

问题

本项目运用:

    simple_mysql_orm: ^1.3.2

simple_mysql_orm 依赖:

    galileo_mysql: ^3.0.0

在代码运转过程中:

Future _handleData(Buffer buffer) async {
   _readyForHeader = true;
   _headerBuffer.reset();
   try {
     var response = _handler?.processResponse(buffer);
     if (_handler is HandshakeHandler) {
       _useCompression = (_handler as HandshakeHandler).useCompression;
       _useSSL = (_handler as HandshakeHandler).useSSL;
     }
     if (response?.nextHandler != null) {
       // if handler.processResponse() returned a Handler, pass control to that handler now
       _handler = response!.nextHandler;
       await sendBuffer(_handler!.createRequest());
       if (_useSSL && _handler is SSLHandler) {
         _log.fine('Use SSL');
         await _socket.startSSL();
         _handler = (_handler as SSLHandler).nextHandler;
         await sendBuffer(_handler!.createRequest());
         _log.fine('Sent buffer');
         return;
       }
     }
     if (response?.finished == true) {
       _log.fine('Finished $_handler');
       _finishAndReuse();
     }
     if (response?.hasResult == true) {
       if (_completer?.isCompleted == true) {
         _completer?.completeError(StateError('Request has already completed'));
       }
       _completer?.complete(response!.result);
     }
   } on MySqlException catch (e, st) {
     // This clause means mysql returned an error on the wire. It is not a fatal error
     // and the connection can stay open.
     _log.fine('completing with MySqlException: $e');
     _finishAndReuse();
     handleError(e, st: st, keepOpen: true);
   } catch (e, st) {
     // Errors here are fatal_finishAndReuse();
     handleError(e, st: st);
   }
 }

总是在这儿handleError抛出反常 MySqlException:

An exception is thrown when this line of code is executed

MySQL Client Error: Authentication plugin not supported: caching_sha2_password

试了这种办法不行:

ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
configure MySQL 8.0 to run in mysql_native_password mode  
<https://medium.com/@crmcmullen/how-to-run-mysql-8-0-with-native-password-authentication-502de5bac661>

because in MySQL 8.0 caching_sha2_password is the default authentication plugin rather than mysql_native_password, which is the default method in MySQL 5.7 and prior.

所以删去mysql-8.0.33 版别从头装置 5.x的版别试试。

5.7.x版别

选择mysql版别: downloads.mysql.com/archives/co…

选择mac os版别点击下载macOS 10.14 (x86, 64-bit), DMG Archive

mysql发动方式

从体系设置发动

在Mac上安装MySQL并在本地部署58fair热更新服务器

假如无法发动运用命令发动

运用命令发动首次发动

首次发动执行命令 mysql_secure_installation

参考点击跳转

mysql_secure_installation 假如遇到过错:

Securing the MySQL server deployment.
Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql.server 我装置后的目录在: /usr/local/mysql-5.7.30-macos10.14-x86_64/support-files/mysql.server

执行mysql.server 发动mysql服务:

 ./mysql.server start

执行 mysql_secure_installation 进行数据库设置: 创立root 用户,设置用户暗码,

axx@huchudeMacBook-Pro mysql % mysql_secure_installation
Securing the MySQL server deployment.
 // 设置数据库root 用户的暗码:
Enter password for user root: 
The existing password for the user account root has expired. Please set a new password.
New password: 
Re-enter new password: 
 // 建立暗码验证插件, 暗码要求满足杂乱,用no 运用弱暗码
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
// 删去匿名用户,这儿用y ,删去匿名用户
 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
// 禁止远程登录,这儿用n,允许
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
 ... skipping.
 //删去测验数据表 这儿用n ,不删去
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
 ... skipping.
 //是否从头加载权限表, 用y 是的
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done! 

mysql数据库操作

登录衔接数据库

mysql -uroot -p

创立数据库

create DATABASE fairpushserverdb

mysql> create DATABASE fairpushserverdb;
Query OK, 1 row affected (0.01 sec)

切换数据库

use fairpushserverdb;

mysql> use fairpushserverdb;
Database changed

创立表

CREATE TABLE

实例如下:悉数复制,点击回车, 即可。

CREATE TABLE `app_info` (
  `app_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `app_name` varchar(45) DEFAULT NULL COMMENT '项目姓名',
  `app_key` varchar(45) DEFAULT NULL COMMENT '项目唯一标识',
  `app_description` varchar(300) DEFAULT NULL COMMENT '项目描述',
  `app_pic_url` varchar(300) DEFAULT NULL COMMENT '项目图片',
  `user_member` varchar(255) DEFAULT NULL COMMENT '项目成员',
  `patch_list` varchar(255) DEFAULT NULL COMMENT '补丁列表',
  `version_name` varchar(20) DEFAULT NULL COMMENT '版别姓名',
  `remark` varchar(300) DEFAULT NULL COMMENT '版别备注',
  `create_name` varchar(45) DEFAULT NULL COMMENT '创立人',
  `create_time` datetime DEFAULT NULL COMMENT '创立时刻',
  `update_time` datetime DEFAULT NULL COMMENT '更新时刻',
  PRIMARY KEY (`app_id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COMMENT='app项目信息';
CREATE TABLE `online_build` (
  `buildId` int(11) NOT NULL AUTO_INCREMENT COMMENT '在线构建使命id',
  `patchGitUrl` varchar(300) DEFAULT NULL COMMENT '补丁项目git地址',
  `patchGitBranch` varchar(45) DEFAULT NULL COMMENT '补丁项目git分支',
  `patchBuildName` varchar(300) DEFAULT NULL COMMENT '补丁项目构建成功后压缩包称号',
  `flutterVersion` varchar(45) DEFAULT NULL COMMENT '构建项目时运用的flutter版别',
  `buildStatus` int(11) NOT NULL COMMENT '在线构建使命状况 0:成功 1:失利 2:构建中',
  `patchCdnUrl` varchar(300) DEFAULT NULL COMMENT '在线构建使命成功后,资源上传到wos后生成的地址 默以为空传,buildStatus为0时该值有用',
  `errorLogUrl` varchar(300) DEFAULT NULL COMMENT '在线构建使命失利的日志 默以为空传,buildStatus为1时该值有用',
  `buildStartTime` datetime DEFAULT NULL COMMENT '构建使命开端时刻',
  `buildFinishTime` datetime DEFAULT NULL COMMENT '构建使命结束时刻',
  PRIMARY KEY (`buildId`)
) ENGINE=InnoDB AUTO_INCREMENT=93 DEFAULT CHARSET=utf8 COMMENT='在线构建';
CREATE TABLE `operation_record` (
  `record_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `operation_time` datetime DEFAULT NULL COMMENT '操作时刻',
  `operator` varchar(45) DEFAULT NULL COMMENT '操作者',
  `operatio_content` varchar(255) DEFAULT NULL COMMENT '操作内容',
  `app_key` varchar(100) DEFAULT NULL COMMENT 'app唯一表',
  `version_name` varchar(100) DEFAULT NULL COMMENT 'app版别',
  PRIMARY KEY (`record_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='操作记载';
CREATE TABLE `patch_info` (
  `bundle_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '补丁id',
  `app_id` varchar(255) DEFAULT NULL COMMENT '项目id',
  `patchCdnUrl` varchar(300) NOT NULL COMMENT '补丁地址url',
  `status` varchar(10) DEFAULT NULL COMMENT '补丁状况:1下发中,2回滚',
  `remark` varchar(255) DEFAULT NULL COMMENT '补丁备注',
  `bundle_version` varchar(20) DEFAULT NULL COMMENT '版别姓名',
  `version_code` varchar(20) DEFAULT NULL COMMENT '版别号',
  `create_time` datetime DEFAULT NULL COMMENT '创立时刻',
  `update_time` datetime DEFAULT NULL COMMENT '更新时刻',
  `bundle_name` varchar(20) NOT NULL DEFAULT '' COMMENT '补丁姓名',
  `patchGitUrl` varchar(300) DEFAULT NULL COMMENT '补丁项目git地址',
  `patchGitBranch` varchar(45) DEFAULT NULL COMMENT '补丁项目git分支',
  `flutterVersion` varchar(45) DEFAULT NULL COMMENT '构建项目时运用的flutter版别',
  PRIMARY KEY (`bundle_id`)
) ENGINE=InnoDB AUTO_INCREMENT=136 DEFAULT CHARSET=utf8 COMMENT='补丁信息';

查询表:

show tables;

mysql> show tables;
+----------------------------+
| Tables_in_fairpushserverdb |
+----------------------------+
| app_info          |
| online_build        |
| operation_record      |
| patch_info         |
+----------------------------+
4 rows in set (0.00 sec)

删去表

drop table app_info,online_build,operation_record,patch_info;

mysql> drop table app_info,online_build,operation_record,patch_info;
Query OK, 0 rows affected (0.01 sec)

查询用户

select Host,User,plugin from mysql.user;

mysql> select Host,User,plugin from mysql.user;
+-----------+---------------+-----------------------+
| Host   | User     | plugin        |
+-----------+---------------+-----------------------+
| localhost | root     | mysql_native_password |
| localhost | mysql.session | mysql_native_password |
| localhost | mysql.sys   | mysql_native_password |
+-----------+---------------+-----------------------+
3 rows in set (0.01 sec)

总结

本文总结了在Mac上装置MySQL数据库以及进行根本数据库操作的过程,一起解决了在Dart端运用以下第三方库时呈现的反常问题:

  • simple_mysql_orm: ^1.3.2
  • galileo_mysql: ^3.0.0

最终,通过这些过程成功在本地部署了58fair的热更新平台。

在Mac上安装MySQL并在本地部署58fair热更新服务器

在Mac上安装MySQL并在本地部署58fair热更新服务器