zoukankan      html  css  js  c++  java
  • mysql问题-centos7中mysql远程连接问题

    1.起初装上CentOS7后,mysql数据库变为Mariadb数据库。但实际是还是mysql.

    2.用户远程连接该数据库发现连接不了。然后关了SElinux,挺了firewall,发现还是不行。

    3.查阅资料终于解决:

      A.默认root是没有密码的,插入host数据 %,修改密码:

    $ mysql -u root
    mysql> use mysql;
    mysql> INSERT INTO user(host,user,password) VALUES('%','root','');
    mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
    mysql> FLUSH PRIVILEGES;

      使用 slect host,user,password from user; 结果如下:

    Database changed
    MariaDB [mysql]> update user set password = password('cosmysql') where user='root';
    Query OK, 3 rows affected (0.01 sec)
    Rows matched: 5  Changed: 3  Warnings: 0
    
    MariaDB [mysql]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [mysql]> select host,user,password from user;
    +-----------------------+------+-------------------------------------------+
    | host                  | user | password                                  |
    +-----------------------+------+-------------------------------------------+
    | localhost             | root | *F2A7750541679FE9A1CC3ABD453EFC346084637C |
    | localhost.localdomain | root | *F2A7750541679FE9A1CC3ABD453EFC346084637C |
    | 127.0.0.1             | root | *F2A7750541679FE9A1CC3ABD453EFC346084637C |
    | ::1                   | root | *F2A7750541679FE9A1CC3ABD453EFC346084637C |
    | localhost             |      |                                           |
    | localhost.localdomain |      |                                           |
    | %                     | root | *F2A7750541679FE9A1CC3ABD453EFC346084637C |
    +-----------------------+------+-------------------------------------------+
    7 rows in set (0.00 sec)

       B.授权,否则会报 Access denied for user 'root'@'%' to database 'xxx'  的错

    grant all on xxxx.* to 'root'@'%' identified by 'password' with grant option;
    
    xxxx代表创建的数据库;这里的xxxx为mysql,你也可以用*代替xxxx.那样远程登陆就会拥有全部数据库的访问权限.
    password为用户密码,在此为root的密码

    2015年10月18日20:48:53

  • 相关阅读:
    CF431E Chemistry Experiment
    BZOJ 4173: 数学
    BZOJ 2426: [HAOI2010]工厂选址
    BZOJ 2580: [Usaco2012 Jan]Video Game
    BZOJ 4237: 稻草人
    BZOJ 2434: [Noi2011]阿狸的打字机
    BZOJ 3881: [Coci2015]Divljak
    BZOJ 2754: [SCOI2012]喵星球上的点名
    BZOJ 1009: [HNOI2008]GT考试
    BZOJ 3731: Gty的超级妹子树
  • 原文地址:https://www.cnblogs.com/xccnblogs/p/4890240.html
Copyright © 2011-2022 走看看