Docker DeskTop => WSL2 DockerHub

    解决WSL2中Vmmem内存占用过大问题
    1按下Windows + R 键,输入 %UserProfile% 并运行进入用户文件夹

    2新建文件 .wslconfig ,然后记事本编辑

    3 填入以下内容并保存, memory为系统内存上限,这里限制最大2gb,可根据自身电脑配置设置

    阿里云加速

    1. [wsl2]
    2. memory=2GB
    3. swap=0
    4. localhostForwarding=true
    5. shell,输入 wsl --shutdown 来关闭当前的子系统
    6. 科大镜像:https://docker.mirrors.ustc.edu.cn/
    7. 网易:https://hub-mirror.c.163.com/
    8. 阿里云:https://<你的ID>.mirror.aliyuncs.com
    9. 七牛云加速器:https://reg-mirror.qiniu.com

    Dcoker run —name mysql-1 -e MYSQL_ROOT_PASSWORD=123456 -p 9099:9099 -d mysql:5.7.28

    —name : 容器名字 -e:密码 -p:端口 -d:后台执行

    docker ps 查看所有正在跑的容器
    docker kill mysql-1 关掉xx容器
    docker container start mysql-1 重新开启msql-1
    docker rm 删掉

    docker exec -it mysql-1 bash

    -exec: 执行 [execute] -d:分离模式: 在后台运行 -i:即使没有附加也保持STDIN 打开 -t :分配一个伪终端

    mysql -u root -p

    -u:用户名 -p:密码

    show databases; //
    use xxx;
    show tables;
    select * from user;
    drop table xxx; / drop database xxx; // 删除xxx表 / 删除xxx数据库
    insert into user (name,age) values (‘jack’,18) //插入数据
    delete from user where name = ‘jack’; //删除数据
    update user set age = 18 where name = ‘jack’;

    1. var mysql = require('mysql');
    2. var connection = mysql.createConnection({
    3. host : 'localhost',
    4. user : 'root',
    5. password : '123456',
    6. });
    7. connection.connect();
    8. connection.query('CREATE DATABASE IF NOT EXISTS song CHARSET utf8mb4 COLLATE utf8mb4_unicode_520_ci;', function (error, results, fields) {
    9. if (error) throw error;
    10. console.log('创建数据库')
    11. console.log( results);
    12. });
    13. connection.query('use song;');
    14. connection.query(`CREATE TABLE IF NOT EXISTS user(
    15. name text,
    16. age int
    17. )`, function (error, results, fields) {
    18. if (error) throw error;
    19. console.log('创建表')
    20. console.log( results);
    21. });
    22. connection.end();