docker 无法启动 mysql 容器可能的解决办法

启动 mysql:8.* 效果很好,但 mysql:5.7.* 会导致立即 100% 内存消耗,尝试通过以下方法解决。

方法1

  1. 编辑 /lib/systemd/system/containerd.service ,修改 LimitNOFILE=infinityLimitNOFILE=1048576
  2. sudo systemctl daemon-reload
  3. sudo systemctl restart containerd.service

再尝试启动 mysql 容器。

方法2

  1. 编辑 /etc/docker/daemon.json
{
    // 原有配置...
    "default-ulimits": {
        "nofile": {
            "Name": "nofile",
            "Hard": 64000,
            "Soft": 64000
        }
    }
}

2. 重启服务 systemctl restart docker

参考:https://sukbeta.github.io/docker-ulimit-configure/

打印 apk 中的信息

前提是安装了 android studio,在 linux 中,使用以下命令:

~/Android/Sdk/build-tools/33.0.2/aapt dump <app.apk>

其中,33.0.2 要改成自己实际的版本。

在manjaro/archlinux中设置dbeaver指定的java版本

找到 dbeaver 的执行位置,查看它的安装位置:

$ which dbeaver
/usr/bin/dbeaver
$ cat /usr/bin/dbeaver
export GTK_OVERLAY_SCROLLING=0
/usr/lib/dbeaver/dbeaver $@

进入 /usr/lib/dbeaver/ 目录,编辑 dbeaver.ini ,在 -vmargs 上面,添加以下内容:

-vm
/usr/lib/jvm/java-17-openjdk/bin

注意:确保已经安装了dbeaver指定的 jre/jdk 版本,并获取其目录。

docker容器的重启策略

Use a restart policy

To configure the restart policy for a container, use the --restart flag when using the docker run command. The value of the --restart flag can be any of the following:

FlagDescription
noDo not automatically restart the container. (the default)
on-failure[:max-retries]Restart the container if it exits due to an error, which manifests as a non-zero exit code. Optionally, limit the number of times the Docker daemon attempts to restart the container using the :max-retries option.
alwaysAlways restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in restart policy details)
unless-stoppedSimilar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts.

参考:https://docs.docker.com/config/containers/start-containers-automatically/

Manjaro中VMwareWorkstation网卡无法连接的解决办法

提示信息可能像这样:

Could not connect 'Ethernet0' to virtual network '/dev/vmnet0'. More information can be found in the vmware.log file.

Failed to connect virtual device 'Ethernet0'.

尝试以下操作:

  1. 启动网络服务
sudo systemctl restart vmware-networks
  1. 尝试重装内核
# 61 改为自己的版本
yay -S linux61 linux61-headers

重启后再试。

  1. 重置网卡设置
sudo touch /etc/vmware/x && sudo vmware-networks --migrate-network-settings /etc/vmware/x && sudo rm /etc/vmware/x && sudo modprobe vmnet && sudo vmware-networks --start

参考:

  1. https://www.jianshu.com/p/d01e65ea8d09
  2. https://communities.vmware.com/t5/VMware-Workstation-Pro/Network-services-failed-in-Linux-installation-VMware-workstation/td-p/2317431

php 框架执行存储过程(stored procedure) 并获取返回

laravel

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use PDO;

class TestController extends Controller
{
    public function index()
    {
        $pdo = DB::getPdo();
        $int = 1;
        $res = 0;
        $stmt = $pdo->prepare("EXEC dbo.test :int,:res");
        $stmt->bindParam(':int', $res, PDO::PARAM_INT);
        $stmt->bindParam(':res', $res, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 400);
        $stmt->execute();
        dd($res);
    }
}

参考:

  • https://stackoverflow.com/questions/71321858/api-laravel-call-store-procedure-with-in-and-out-parameter-using-oci8-or-pdo
  • https://laracasts.com/discuss/channels/general-discussion/running-stored-procedures

thinkphp 5.0

tp5 需要修改原码才可以使用:

  • 找到文件 thinkphp/library/think/db/Connection.php
  • 第 388 行,在 catch (\PDOException $e) 内,修改为如下代码:
    if ($procedure == true) { return; } elseif ($this->isBreak($e)) { return $this->close()->query($sql, $bind, $master, $pdo); }

控制器执行:

<?php

namespace app\api\controller;

use PDO;
use think\Db;

class Test extends Common {
    public function index() {
        $int = 1;
        $res = 1;
        Db::query('exec test :int,:res', [
            'int' => $int,
            'res' => [&$res, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 4000],
        ]);
        print_r($res);
    }
}

参考:

  • https://blog.csdn.net/Drug_/article/details/95474776

以上示例使用的存储过程如下:

ALTER PROC [dbo].[test]
-- 创建:CREATE PROC [dbo].[test]
 @IntInput int,
 @StrResult varchar(20) out
as
begin
         if (@IntInput>1)
           Set
        @StrResult = '>1'
        else 
            Set
        @StrResult = '<=1'
end

SQL 执行:

declare @strResult varchar(20)
exec test -1,@strResult output
print @strResult