ubuntu中连接mysql失败的解决方法

原因:Ubuntu在mysql的配置文件中默认绑定了本机ip,需要修改配置文件并赋予权限。

1.在ubuntu命令行中,打开my.cnf配置文件;

/etc/mysql/my.cnf

2.my.cnf配置文件打开后,在文件进行以下修改:

# Instead of skip-networking the default is now to listen only on# localhost which is more compatible and is not less secure.bind-address = 127.0.0.1

3.my.cnf配置文件修改好后,使用service命令启动MySQL;

service mysql start

4.最后,MySQL启动后,使用root用户即可连接到MySQL;

mysql -u root -p