安装好MySQL之后,如果需要远程连接,那么需要做一些配置,否则会出现一些类似的错误,如
mysql root用户ERROR 1045 (28000): mysql 远程登录 ERROR 1045 (28000) mysql 远程登录2003
Can not connect to mysql error 10061
1 当MySQL 连接服务器时发生”Can not connect to mysql error 10061”错误
将/etc/mysql/my.conf文件中的bind-address选项设置为MySQL服务器的IP,默认为127.0.0.1。
然后sudo /etc/init.d/mysql restart --重启服务
2 当MySQL 连接服务器时发生”is not allowed to connect to this MySQL server”错误
将MySQL数据库中的user表中的host列的localhost为%
delete from user where user='root' and host <> '%'; -- 删除多余用户 update user set host ='%' where host='localhost' and user='root'; --更新host select host,user,password from user;
+-----------+------------------+-------------------------------------------+ | host | user | password | +-----------+------------------+-------------------------------------------+ | localhost | debian-sys-maint | *3B3724AE1051D0628525347DAC3635A6C523F944 | | % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | % | hive | *4DF1D66463C18D44E3B001A8FB1BBFBEA13E27FC | +-----------+------------------+-------------------------------------------+
3 此时没有127.0.0.1和localhost主机,所以无法用root用户进行连接,会提示以下错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
则此时只能用系统自带的debian-sys-maint用户登录,给root用户赋予新的权限。debian-sys-maint用户的的登录密码在/etc/mysql/debian.cnf中明文显示。
grant all on *.* to root@'%' identified by 'user_password';
4 如果不想root用户被远程登录,可以新建用户
mysql -u root -p insert into user(Host,User,Password) values("%","hive",password("hive")); FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY 'hive'; FLUSH PRIVILEGES;