For some reason, I've been unable to connect remotely to my MySQL server. I've tried everything and I'm still getting errors.

root@server1:/home/administrator# mysql -u monty -p -h www.ganganadores.cl
Enter password:
ERROR 1045 (28000): Access denied for user 'monty'@'server1.ganganadores.cl' (using password: YES)

Now, I've tried running

 GRANT ALL ON *.* to monty@localhost IDENTIFIED BY 'XXXXX'; 
 GRANT ALL ON *.* to monty@'%' IDENTIFIED BY 'XXXXXX';` 

and still nothing! What I'm doing wrong?

EDIT: my.cnf has commented out the bind ip .

推荐答案

To expose MySQL to anything other than localhost you will have to have the following line

For mysql version 5.6 and below

uncommented in /etc/mysql/my.cnf and assigned to your computers IP address and not loopback

For mysql version 5.7 and above

uncommented in /etc/mysql/mysql.conf.d/mysqld.cnf and assigned to your computers IP address and not loopback

#Replace xxx with your IP Address 
bind-address        = xxx.xxx.xxx.xxx

Or add a bind-address = 0.0.0.0 if you don't want to specify the IP

Then stop and restart MySQL with the new my.cnf entry. Once running go to the terminal and enter the following command.

lsof -i -P | grep :3306

That should come back something like this with your actual IP in the xxx's

mysqld  1046  mysql  10u  IPv4  5203  0t0  TCP  xxx.xxx.xxx.xxx:3306 (LISTEN)

If the above statement returns correctly you will then be able to accept remote users. However for a remote user to connect with the correct priveleges you need to have that user created in both the localhost and '%' as in.

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';

then,

GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';

and finally,

FLUSH PRIVILEGES; 
EXIT;

If you don't have the same user created as above, when you logon locally you may inherit base localhost privileges and have access issues. If you want to restrict the access myuser has then you would need to read up on the GRANT statement syntax HERE If you get through all this and still have issues post some additional error output and the my.cnf appropriate lines.

NOTE: If lsof does not return or is not found you can install it HERE based on your Linux distribution. You do not need lsof to make things work, but it is extremely handy when things are not working as expected.

UPDATE: If even after adding/changing the bind-address in my.cnf did not work, then go and change it in the place it was originally declared:

/etc/mysql/mariadb.conf.d/50-server.cnf

Mysql相关问答推荐

正在获取MySQL死锁,因为这个查询需要很长时间.

使用由其中一个表的列规定的条件连接两个表

如何在Sequelize中将查询作为选项?

带有值分隔的MySQL分组不起作用

Mysql,从两个不同的表中添加原始数据,从第一个表中获取所有内容,仅从第二个表中获取curdate内容

在带有 D.I 的 .NET AWS Lambda 中使用 MySql.Data

如何找到每个user_id每个产品的买家类型数量?

如何在 Shopware 6 DAL 中实施 Haversine 公式?

如何编写一个查询,计算表中每个日期的一个日期加上前 4 天的记录数?

有人可以帮我优化这个查询吗?

为什么 fetch 方法不能获取任何东西?(feat node.js,restAPI)

在 postgresql 中实现 UML 类:创建类型与创建表

MYSQL LOAD DATA INFILE 语句适用于工作台,但不适用于 python

Facebook user_id:big_int、int 还是 string?

MySQL触发器在某些条件下防止INSERT

MySQL如何为数据库中的所有表生成DDL

使用 MySql,我可以对列进行排序但最后有 0 吗?

电话号码和地址的mysql数据类型

"SELECT COUNT(*)" 很慢,即使有 where 子句

什么是mysql的BETWEEN性能超过..?