[root@linux ~]# mysql -u root -p 123456
Enter password:
ERROR 1049 (42000): Unknown database ‘123456‘
[root@linux ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> select user,host from mysql.user
-> ;
+------+-----------+
| user | host |
+------+-----------+
| root | % |
| root | 127.0.0.1 |
| | linux |
| root | linux |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)
mysql>
mysql> select user,host from mysql.user
-> ;
+------+-----------+
| user | host |
+------+-----------+
| root | % |
| root | 127.0.0.1 |
| | linux |
| root | linux |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)
mysql> grant select,insert,update,delete on *.* to test1@"%" Identified by "abc"
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user
-> ;
+-------+-----------+
| user | host |
+-------+-----------+
| root | % |
| test1 | % |
| root | 127.0.0.1 |
| | linux |
| root | linux |
| | localhost |
| root | localhost |
+-------+-----------+
7 rows in set (0.00 sec)
mysql>
mysql> grant select,insert,update,delete on book.* to test2@localhost Identified by "abc";
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user
-> ;
+-------+-----------+
| user | host |
+-------+-----------+
| root | % |
| test1 | % |
| root | 127.0.0.1 |
| | linux |
| root | linux |
| | localhost |
| root | localhost |
| test2 | localhost |
+-------+-----------+
8 rows in set (0.00 sec)
只能用test2 (abc)在php里,
3、增加用户:
(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”
第一种:
增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MYSQL,然后键入以下命令:
grant select,insert,update,delete on *.* to test1@“%” Identified by “abc”;
但增加的用户是十分危险的,你想如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的mysql数据库并对你的数据可以为所欲为了,解决办法见例第二种:
第一种:增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操 作(localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数
mysql> grant select,insert,update,delete on book.* to test2@localhost Identified by "abc";
如果你不想test2有密码,可以再打一个命令将密码消掉。
mysql> grant select,insert,update,delete on book.* to test2@localhost Identified by "";
原文地址:http://www.cnblogs.com/kylegui/p/3798884.html