mysql:賦予用戶權限、查看及修改端口號


一、mysql 賦給用戶權限

grant all privileges on *.* to joe@localhost identified by '1';

flush privileges;

即用user=joe    password=1 登陸

附:

mysql> grant 權限1,權限2,…權限n on 數據庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連接口令’;
權限1,權限2,…權限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個權限。
當權限1,權限2,…權限n被all privileges或者all代替,表示賦予用戶全部權限。
當數據庫名稱.表名稱被*.*代替,表示賦予用戶操作服務器上所有數據庫所有表的權限。
用戶地址可以是localhost,也可以是ip地址、機器名字、域名。也可以用’%'表示從任何地址連接。
‘連接口令’不能為空,否則創建失敗。

示例:

1>mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的用戶joe分配可對數據庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的權限,並設定口令為123。

2>mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的用戶joe分配可對數據庫vtdc所有表進行所有操作的權限,並設定口令為123。

3>mysql>grant all privileges on *.* to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令為123。

4>mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;

給本機用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令為123。

二、查看端口號

1. 登錄mysql 

[root@test /]# mysql -u root -p 

Enter password: 

2. 使用命令show global variables like 'port';查看端口號 

mysql> show global variables like 'port'; 

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

| Variable_name | Value | 

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

| port | 3306 | 

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

1 row in set (0.00 sec) 

三、修改端口號

1. 修改端口,編輯/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口參數,並且設定端口,注意該端口未被使用,保存退出。 

[root@test etc]# vi my.cnf 

[mysqld] 

port=3506

datadir=/var/lib/mysql 

socket=/var/lib/mysql/mysql.sock 

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks 

symbolic-links=0

[mysqld_safe] 

log-error=/var/log/mysqld.log 

pid-file=/var/run/mysqld/mysqld.pid 

……

2. 重新啟動mysql 

[root@test ~]# /etc/init.d/mysqld restart 

Stopping mysqld: [ OK ] 

Starting mysqld: [ OK ] 

3.再次登錄后檢查端口已修改為’3506’. 

[root@test etc]# mysql -u root -p 

Enter password: 

mysql> show global variables like 'port'; 

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

| Variable_name | Value | 

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

| port | 3506 | 

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

1 row in set (0.00 sec) 

mysql>

總結:注意修改的端口不要被占用,而且要有規划,不要輕意的總是調整數據庫端口。還有就是安全保障,記得與負責網絡的人提前通知,以免端口無法正常使用。  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM