mysql 远程 ip访问
2015-08-26 09:33
344 查看
默认情况下Linux内的mysql数据库mysql,user表内的用户权限只是对localhost即本机才能登陆。需要更改权限:
如下的方式确认:
root#mysql -h localhost-u mysql -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
6 rows in set (0.02 sec)
由此可以看出,只能以localhost的主机方式访问。
解决方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by ‘password’with grant option;
(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,)
mysql> flush privileges; (运行为句才生效,或者重启MySQL)
Query OK, 0 rows affected (0.03 sec)
mysql> select host,user from user; (再次查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| % | mysql |
| % | root |
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
mysql>exit
现在再试试:
root#mysql -h mysql -u root -p
Enter password:******
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
就成功连接上了。
如下的方式确认:
root#mysql -h localhost-u mysql -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
6 rows in set (0.02 sec)
由此可以看出,只能以localhost的主机方式访问。
解决方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by ‘password’with grant option;
(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,)
mysql> flush privileges; (运行为句才生效,或者重启MySQL)
Query OK, 0 rows affected (0.03 sec)
mysql> select host,user from user; (再次查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| % | mysql |
| % | root |
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
mysql>exit
现在再试试:
root#mysql -h mysql -u root -p
Enter password:******
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 9 to server version: 4.0.20a-debug
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
就成功连接上了。
相关文章推荐
- MySQL备份脚本
- mysqld Can’t start server : Bind on unix socket: Permission denied
- MYSQL用户创建删除和权限问题
- MySQL 配置参数详解
- MySQL 数据库连接失败 SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)
- MySQL查询当前数据上一条和下一条的记录
- LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1
- LeetCode 175 Combine Two Tables mysql,left join 难度:0
- 2015年1月最新中国行政区划县及以上代码mysql数据库
- MYSQL 多表更新 UPDATE SET like concat('%',abc,'%');
- mysql 锁
- mysql手工添加windows服务
- mysql 错误注意事项
- mysql文档摘要续4
- MySQL的redo log结构和SQL Server的log结构对比
- mybatis+mysql返回插入值后的主键id
- 三种方法链接MySQL
- Mysql安装及1067错误相关
- MySQL优化---DBA对MySQL优化的一些总结
- MySQL数据类型和常用字段属性总结