1、mysql -u root -p (root)用戶名
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
3、mysql>flush privileges;
4、如果此時還無法連接,檢測配置文件(/etc/mysql/mysql.conf.d/mysqld.cnf) bind-address配置是否開啟,應該是關閉
#bind-address = 127.0.0.1 注釋掉;
# 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 <----這個
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
5、重啟mysql:/etc/init.d/mysql restart;