mysql: [Warning] Using a password onthe command line interface can be insecure. ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.104' (111)
解决方案:
1、授予远程登录权限 grant all privileges on *.* To '用户名'@'%' identified by '密码' with grant option; -- 5.7 后加用户名登录验证插件 如果密码过于简单 可能会出现(如果没有可直接进行第二步): ERROR 1819 (HY000): Your password doesnot satisfy the current policy requirements -- 验证解决方案 mysql> select @@log_error; +---------------------+ | @@log_error | +---------------------+ | /var/log/mysqld.log | +---------------------+ 1 row inset (0.00 sec) mysql> setglobal validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> setglobal validate_password_mixed_case_count=2; Query OK, 0 rows affected (0.00 sec) mysql> setglobal validate_password_length=4; Query OK, 0 rows affected (0.00 sec) mysql> setglobal validate_password_special_char_count=0; Query OK, 0 rows affected (0.00 sec) mysql> SHOW VARIABLES LIKE 'validate_password%'; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_dictionary_file | | | validate_password_length | 4 | | validate_password_mixed_case_count | 2 | | validate_password_number_count | 0 | | validate_password_policy | LOW | | validate_password_special_char_count | 0 | +--------------------------------------+-------+ 6 rows inset (0.00 sec) mysql> flush privileges; -- 重新远程授权 mysql> grant all privileges on *.* To '用户名'@'%' identified by '密码' with grant option; Query OK, 0 rows affected (0.00 sec) mysql>exit
5、重启mysql服务 whl@whl: service mysql restart whl@whl:/etc/mysql$ mysql -h192.168.1.104 -uroot -pXXX mysql: [Warning] Using a password onthe command line interface can be insecure. Welcome tothe MySQL monitor. Commands endwith ; or \g. Your MySQL connection idis4 Server version: 5.7.17-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
6、如果连接还出现失败就要查看端口号是否为3306 mysql> show variables; | port | 3306 whl@whl: sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf (修改配置文件中的端口号即可,然后重启服务即可)