zoukankan      html  css  js  c++  java
  • 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 getEnv不区分大小写 getProperty区分大小写
    spring 解析配置文件问题
    (转载)Java里快如闪电的线程间通讯
    quartz中关键类
    HTTP中缓存相关
    (转载)javascript函数作用域和提前声明
    (转载)ETL利器Kettle实战应用解析系列一【Kettle使用介绍】
    rcnn 理解笔记
    打乱图片顺序,按一定比例分别存放
    Python 批量读取文件夹下的图片,并保存在文档下
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/8872674.html
Copyright © 2011-2022 走看看