资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

lamporlnmp环境搭建之独立安装mysql数据库

lamp or lnmp 环境搭建,如果MySQL 是独立安装的则需要授权:

成都创新互联公司于2013年创立,先为蓬溪等服务建站,蓬溪等地企业,进行企业商务咨询服务。为蓬溪企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

  1. 单独一台服务器独立安装mysql

  2. 安装后,优化服务器。

  3. 授权

实例一:

#创建用户demo,密码demo123

mysql> create user demo@localhost identified by 'demo123';

Query OK, 0 rows affected (0.00 sec)

#此时只能登录,因为没有授权

mysql> show grants for demo@localhost;  

+----------------------------------------------------------------------------------------------------------------+

| Grants for demo@localhost                                                                                   |

+----------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'demo'@'localhost' IDENTIFIED BY PASSWORD '*2CADADD54086D5EB4C9F10E0430084D7F179885C' |

+----------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

#授权本地登录

mysql> grant all on test.* to 'demo'@'localhost';

Query OK, 0 rows affected (0.01 sec)

#查看授权情况

mysql> show grants for demo@localhost;           

+----------------------------------------------------------------------------------------------------------------+

| Grants for demo@localhost                                                                                   |

+----------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'demo'@'localhost' IDENTIFIED BY PASSWORD '*2CADADD54086D5EB4C9F10E0430084D7F179885C' |

| GRANT ALL PRIVILEGES ON `test`.* TO 'demo'@'localhost'                                                      |

+----------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

-------------------------------------------------------------------------------------------

实例二

授权所有的数据库给myuser从局域网10.89.1.0网段上连接

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'10.89.1.%'IDENTIFIED BY 'mypassword'; 

FLUSH PRIVILEGES;

mysql> select user,host from mysql.user;

+---------+-------------+

| user    | host        |

+---------+-------------+

| tom     | %           |

| tom1    | %           |

| tom2    | %           |

| root    | 127.0.0.1   |

| myuser  | 10.89.1.%   |

| myuser  | localhost   |

| myuser  | localhost   |

| root    | localhost   |

| tom     | localhost   |

| root    | mysql       |

+---------+-------------+

10 rows in set (0.01 sec)

#客户端连接测试

#如果是默认的3306 就不需要加,这里是使用多实例测试,端口是3308。

[root@weblnmp ~]# mysql -umyuser -pmypassword -h 10.89.1.30 -P3308; 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.5.32-log 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> 

5.web服务器连接测试

[root@weblnmp blog]# vi test_mysql.php

   

     $link_id=mysql_connect('10.89.1.30','myuser','mypassword') or mysql_error();

      if ($link_id) {

             echo "mysql _OK()";

         }

    else {

             echo "mysql _error()";

         }

  ?>


名称栏目:lamporlnmp环境搭建之独立安装mysql数据库
当前链接:http://cdkjz.cn/article/podoes.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220