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

posted @ 2015-10-18 20:50  超超xc  Views(2425)  Comments(0Edit  收藏  举报
I suppose,were childrenonec.