cre..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

lamp or lnmp 環(huán)境搭建之獨(dú)立安裝mysql數(shù)據(jù)庫

發(fā)布時間:2020-07-06 09:15:55 來源:網(wǎng)絡(luò) 閱讀:3173 作者:ahtornado 欄目:數(shù)據(jù)庫

lamp or lnmp 環(huán)境搭建,如果mysql 是獨(dú)立安裝的則需要授權(quán):

  1. 單獨(dú)一臺服務(wù)器獨(dú)立安裝mysql

  2. 安裝后,優(yōu)化服務(wù)器。

  3. 授權(quán)

實(shí)例一:

#創(chuàng)建用戶demo,密碼demo123

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

Query OK, 0 rows affected (0.00 sec)

#此時只能登錄,因?yàn)闆]有授權(quán)

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)

#授權(quán)本地登錄

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

Query OK, 0 rows affected (0.01 sec)

#查看授權(quán)情況

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)

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

實(shí)例二

授權(quán)所有的數(shù)據(jù)庫給myuser從局域網(wǎng)10.89.1.0網(wǎng)段上連接

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)

#客戶端連接測試

#如果是默認(rèn)的3306 就不需要加,這里是使用多實(shí)例測試,端口是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服務(wù)器連接測試

[root@weblnmp blog]# vi test_mysql.php

   <?php

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

      if ($link_id) {

             echo "mysql _OK()";

         }

    else {

             echo "mysql _error()";

         }

  ?>


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI