抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

大概是因为权限的问题。

今天想试一下typeorm这个框架,先安装,填上配置,我是mysql服务器,在腾讯云上的,以前就启动过了,填上链接,用户名和密码,我确定填的都是正确的,可他就是提示我:

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'123.133.28.245' (using password: YES)

百度到了解决方案,成功解决。

(31条消息) MySQL登录时出现 Access denied for user ‘root’@‘xxx.xxx.xxx.xxx’ (using password: YES) 的原因及解决办法_iw1210的专栏-CSDN博客

  1. 先用localhost登录

    # mysql -u root -p
    Enter password: 
    
  2. 执行授权命令

    mysql> grant all privileges on *.* to root@'%' identified by '123';
    Query OK, 0 rows affected (0.07 sec)
    
  3. 退出再试

    mysql> quit
    Bye
    
    
  4. 再试登录:

    # mysql -u root -h 192.168.194.142 -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.6.33 MySQL Community Server (GPL)
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    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.
    

————————————————
版权声明:本文为CSDN博主「iw1210」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/iw1210/article/details/54646093

成功链接!

import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "./entity/User";

createConnection().then(async connection => {

    console.log("Inserting a new user into the database...");
    const user = new User();
    user.firstName = "Timber";
    user.lastName = "Saw";
    user.age = 25;
    await connection.manager.save(user);
    console.log("Saved a new user with id: " + user.id);

    console.log("Loading users from the database...");
    const users = await connection.manager.find(User);
    console.log("Loaded users: ", users);

    console.log("Here you can setup and run express/koa/any other framework.");

}).catch(error => console.log(error));

output:

PS C:\myfile\project\typeorm\demo1> yarn start
yarn run v1.22.10
warning package.json: No license field
$ ts-node src/index.ts
Inserting a new user into the database...
Saved a new user with id: 1
Loading users from the database...
Loaded users:  [ User { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 } ]
Here you can setup and run express/koa/any other framework.

评论