• mysql创建用户,并授予权限


    mysql> GRANT ALL PRIVILEGES ON *.* TO jiqing@"%" IDENTIFIED BY '123456';
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    

    这两条指令的作用,是创建用户jiqing,密码是123456。所有ip都可以访问。并授予这个用户所有的权限,刷新生效。

    同时在/etc/hosts中,将阿里云的mysql地址加入其中。

    127.0.0.1    rm-wz94y9juv07017s60.mysql.rds.aliyuncs.com
    

    关于hosts,我们本机有hosts,路由中也有hosts,路由中设置了hosts,就相当于所有的电脑都设置了。

    jiqing@ubuntu:/usr/local/nginx/conf/vhost$ ping jiqing.sheep.5hao.com
    PING jiqing.sheep.5hao.com (192.168.199.126) 56(84) bytes of data.
    64 bytes from jiqing.hotel.caomall.net (192.168.199.126): icmp_seq=1 ttl=64 time=0.047 ms
    64 bytes from jiqing.hotel.caomall.net (192.168.199.126): icmp_seq=2 ttl=64 time=0.052 ms
    64 bytes from jiqing.hotel.caomall.net (192.168.199.126): icmp_seq=3 ttl=64 time=0.052 ms
    64 bytes from jiqing.hotel.caomall.net (192.168.199.126): icmp_seq=4 ttl=64 time=0.052 ms
    
    jiqing@ubuntu:/usr/local/nginx/conf/vhost$ ping local.sheep.5hao.com
    PING local.sheep.5hao.com (127.0.0.1) 56(84) bytes of data.
    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.057 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.052 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.050 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.053 ms
    

    这两个都是路由中的hosts设置的,如果我把自己本地的jiqing.sheep.5hao.com更改成192.168.199.127。看看效果。

    jiqing@ubuntu:/usr/local/nginx/conf/vhost$ ping jiqing.sheep.5hao.com
    PING jiqing.sheep.5hao.com (192.168.199.127) 56(84) bytes of data.
    From jiqing.hotel.caomall.net (192.168.199.126) icmp_seq=1 Destination Host Unreachable
    From jiqing.hotel.caomall.net (192.168.199.126) icmp_seq=2 Destination Host Unreachable
    From jiqing.hotel.caomall.net (192.168.199.126) icmp_seq=3 Destination Host Unreachable
    From jiqing.hotel.caomall.net (192.168.199.126) icmp_seq=4 Destination Host Unreachable
    

    会发现,如果ping不通,它就会去路由中找。
    再次改为127.0.0.1

    jiqing@ubuntu:/usr/local/nginx/conf/vhost$ ping jiqing.sheep.5hao.com
    PING jiqing.sheep.5hao.com (127.0.0.1) 56(84) bytes of data.
    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.056 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.051 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.047 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.052 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.046 ms
    

    会发现,如果ping通了,就优先执行本地的ip。很有意思。

    这样就可以实现,同样的代码。可以连接本地的数据库。即便上传到了服务器,一样可以正常使用。

    这其实是造假吧,访问的并不是阿里云的mysql数据库,而是本地的数据库。

    线上的服务器,也要这么造假,访问的也不是阿里云的数据库,而是它自己的数据库。

    经过这样造假之后,本地和线上的数据库配置就都不需要更改了。

        'DB_HOST'                   =>  'rm-wz94y9juv07017s60.mysql.rds.aliyuncs.com', // 数据库host
        'DB_NAME'                   =>  'xxx',                                    // db name
        'DB_USER'                   =>  'jiqing',                                  // 用户名
        'DB_PWD'                    =>  '123456',                               // 密码
    
  • 相关阅读:
    java 下载文件
    springfox-swagger之swagger-bootstrap-ui
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    An internal error occurred during: Initializing Java Tooling.
    hexo 报错 Cannot read property 'replace' of null
    点击此电脑,查看属性获取计算机的基本信息,可以获取那些计算机基础知识信息呢
    微信、qq可以上网,但是浏览器却不能上网怎么办
    maven打包如何跳过测试
    Ubuntu16.04安装和配置RabbitMQ
    Jenkins持续集成实践之java项目自动化部署
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/8872674.html
Copyright © 2020-2023  润新知