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
问题
本项目使用:
markdown
simple_mysql_orm: ^1.3.2
simple_mysql_orm 依赖:
markdown
galileo_mysql: ^3.0.0
在代码运行过程中:
ini
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
试了这种方法不行:
sql
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启动方式
从系统设置启动
如果无法启动使用命令启动
使用命令启动首次启动
首次启动执行命令 mysql_secure_installation
mysql_secure_installation 如果遇到错误:
vbnet
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服务:
bash
./mysql.server start
执行 mysql_secure_installation 进行数据库设置: 创建root 用户,设置用户密码,
sql
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
sql
mysql> create DATABASE fairpushserverdb;
Query OK, 1 row affected (0.01 sec)
切换数据库
use fairpushserverdb;
ini
mysql> use fairpushserverdb;
Database changed
创建表
CREATE TABLE
实例如下:全部复制,点击回车, 即可。
less
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;
sql
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;
sql
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;
sql
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的热更新平台。