1. 程式人生 > >Mysql 本地登陸和密碼登陸

Mysql 本地登陸和密碼登陸

mysql> create user [email protected]'10.130.128.130' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

-bash-4.1$ mysql -uczcb         
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.6.16 Source distribution

Copyright (c) 2000, 2014, 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> 

-bash-4.1$ mysql -uczcb -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'czcb'@'localhost' (using password: YES)


新建使用者後 客戶端登陸會報1045錯誤

mysql> grant select,insert,update on test.* to 'czcb'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from mysql.user where user='czcb';
+----------------+------+-------------------------------------------+
| host           | user | password                                  |
+----------------+------+-------------------------------------------+
| 10.130.128.130 | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| %              | czcb |                                           |
+----------------+------+-------------------------------------------+
2 rows in set (0.00 sec)

需要做:
grant select,insert,update on test.* to 'czcb'@'%' identified by '123456';


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from mysql.user where user='czcb';
+----------------+------+-------------------------------------------+
| host           | user | password                                  |
+----------------+------+-------------------------------------------+
| 10.130.128.130 | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| %              | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+----------------+------+-------------------------------------------+
2 rows in set (0.00 sec)



此時本地還是無法用密碼登陸:
-bash-4.1$ mysql -uczcb -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'czcb'@'localhost' (using password: YES)


grant select,insert,update on test.* to 'czcb'@localhost identified by '123456';



此時可以:
-bash-4.1$ mysql -uczcb -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 96
Server version: 5.6.16 Source distribution

Copyright (c) 2000, 2014, 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> 

mysql> select host,user,password from mysql.user where user='czcb';
+----------------+------+-------------------------------------------+
| host           | user | password                                  |
+----------------+------+-------------------------------------------+
| 10.130.128.130 | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| %              | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost      | czcb | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+----------------+------+-------------------------------------------+
3 rows in set (0.00 sec)