当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql如何开启远程访问服务?

mysql如何开启远程访问服务?

2018年11月04日  | 移动技术网IT编程  | 我要评论

mysql -u root -p

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 6

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, 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.

mysql> use mysql;

database changed

mysql> select host,user,password from user;

+———–+——+——————————————-+

| host | user | password |

+———–+——+——————————————-+

| localhost | root | *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 |

| 127.0.0.1 | root | |

| ::1 | root | |

| localhost | | |

+———–+——+——————————————-+

4 rows in set (0.00 sec)

mysql> update user set host=’%’ where user=’root’;

error 1062 (23000): duplicate entry ‘%-root’ for key ‘primary’

mysql> update user set host=’ %’ where user=’root’;

error 1062 (23000): duplicate entry ’ %-root’ for key ‘primary’

mysql> select host,user from user where user=’root’;

+———–+——+

| host | user |

+———–+——+

| % | root |

| 127.0.0.1 | root |

| ::1 | root |

+———–+——+

3 rows in set (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.02 sec)

mysql> quit;

bye

./etc/init.d/mysql restart

shutting down mysql. [ ok ]

starting mysql. [ ok ]

mysql -u root -p

error 1045 (28000): access denied for user ‘root’@’localhost’ (using password: y

es)

mysql -u root -p

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 6

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, 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.

mysql> exit;

bye

mysqladmin -uroot password 123456

mysql -uroot -p123456

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 6

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, 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.

mysql> grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with gra

nt option;

query ok, 0 rows affected (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

解释下上面遇到的问题:

1.首先查询有没有开启远程访问(可以让任意ip通过root用户访问)

2.没有开启,则修改host=’%’,会报错:error 1062 (23000): duplicateentry ’ %-root’for key’primary’

3.忽略第二个问题,并flush privileges;(刷新mysql权限相关表,否则会报错:拒绝访问)

4.通过命令重新登录报错:error 1045 (28000): access denied for user ‘root’@’localhost’ (using password: yes),原因是密码变成空了,重新设置密码:mysqladmin -uroot password 123456

5.这个时候访问还是报错: host ip is not allowed to connect to this mysql。通过以下两个命令即可解决,grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;flush privileges;

如对本文有疑问, 点击进行留言回复!!

相关文章:

  • MySQL InnoDB表空间加密示例详解

    前言从 mysql5.7.11开始,mysql对innodb支持存储在单独表空间中的表的数据加密 。此功能为物理表空间数据文件提供静态加密。该加密是在引擎内部数... [阅读全文]
  • 如何解决mysql无法关闭的问题

    如何解决mysql无法关闭的问题

    mysql关闭不了的解决办法:右键点击电脑的任务栏,打开任务管理器点击服务,找到mysql服务右键点击该服务,选择停止就可以了内容扩展:mac系统mysqld进... [阅读全文]
  • mysql不是内部命令的错误解决方案

    mysql不是内部命令的错误解决方案

    出现mysql不是内部命令的错误是因为没有把mysql的bin目录路径添加到环境变量中解决方法:打开电脑的环境变量,选择系统变量,打开path,将mysql的b... [阅读全文]
  • 关于MySQL主从复制的几种复制方式总结

    关于MySQL主从复制的几种复制方式总结

    异步复制mysql的复制默认是异步的,主从复制至少需要两个mysql服务,这些mysql服务可以分布在不同的服务器上,也可以在同一台服务器上。mysql主从异步... [阅读全文]
  • 详细分析MySQL主从复制

    详细分析MySQL主从复制

    前言:在mysql中,主从架构应该是最基础、最常用的一种架构了。后续的读写分离、多活高可用架构等大多都依赖于主从复制。主从复制也是我们学习mysql过程中必不可... [阅读全文]
  • MySQL单表恢复的步骤

    正休息的时候一个电话将我的睡意完全打散,“开发童鞋写update sql的时候忘了加where条件了”,相信每一个dba同学听到这个消息的时候都有骂街的冲动吧。... [阅读全文]
  • MySQL性能优化之如何高效正确的使用索引

    实践是检验真理的唯一途径,本篇只是站在索引使用的全局来定位的,你只需要通读全篇并结合具体的例子,或回忆以往使用过的地方,对整体有个全面认识,并理解索引是如何工作... [阅读全文]
  • MySQL如何优化查询速度

    前面章节我们介绍了如何选择优化的数据类型、如何高效的使用索引,这些对于高性能的mysql来说是必不可少的。 但这些还完全不够,还需要合理的设计查询。 如果查询写... [阅读全文]
  • MySQL优化SQL语句的技巧

    在面对不够优化、或者性能极差的sql语句时,我们通常的想法是将重构这个sql语句,让其查询的结果集和原来保持一样,并且希望sql性能得以提升。而在重构sql时,... [阅读全文]
  • 简述MySql四种事务隔离级别

    隔离级别:隔离性其实比想象的要复杂。 在sql标准中定义了四种隔离级别, 每一个事务中所做的修改,哪些在事务内和事务间是可见的,哪些是不可见的。较低级别的隔离通... [阅读全文]
验证码:
移动技术网