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>

总结:注意修改的端口不要被占用,而且要有规划,不要轻意的总是调整数据库端口。还有就是安全保障,记得与负责网络的人提前通知,以免端口无法正常使用。  

原文地址:https://www.cnblogs.com/zhangwuji/p/7899375.html