PHP连接MySQL

[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里,

 

mysql 增加用户

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 "";

 

 

转载于:https://www.cnblogs.com/kylegui/p/3798884.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值