设置mysql免密码登录, mysql设置密码


创建文件~/.my.cnf

[client]
host	= 192.168.20.202
user            = web_app
password        = WEB_app~!@`12
port            = 3306
# socket          = /opt/lampp/var/mysql/mysql.sock
database	= easyweb_new_trans

mysql –no-auto-rehash

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1175
Server version: 5.7.25-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
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> show databases;

比较这个命令执行的结果

mysql -h192.168.20.202 -uweb_app --database easyweb_new_trans -p'WEB_app~!@`12' -A -e "show databases"

* 修改~/.my.cnf权限

chmod 600 ~/.my.cnf

mysql设置密码:

use mysql;
update user set password=password('test1111') where user='root' and host='localhost';
update user set password=password('test1111') where user='root' and host='127.0.0.1';
update user set password=password('test1111') where user='root' and host='172.16.0.224';
grant all privileges on *.* to root@'%' identified by 'test1111';
flush privileges;

测试连接:

mysql -uroot -h172.16.0.224 -ptest1111 -A –port 13306