版本:5.7.28
服务器:mysql 192.168.4.20
1.MySQL管理工具 部署LAMP phpMyAdmin平台
安装httpd、mysql、php-mysql及相关包
启动httpd服务程序
解压phpMyAdmin包,部署到网站目录
配置config.inc.php,指定MySQL主机地址
创建授权用户
浏览器访问、登录使用
1.1 准备软件的运行环境 lamp
]# yum -y install httpd php php-mysql
]# systemctl start httpd
]# systemctl enable httpd
]# vim /var/www/html/test.php
<?php
$x=mysql_connect("localhost","root","123456");
if($x){ echo "ok"; }else{ echo "no"; };
?>
]# curl http://192.168.4.20/test.php
ok
1.2 安装phpMyAdmin
]# wget https://files.phpmyadmin.net/snapshots/phpMyAdmin-4.7.0-all-languages.tar.gz
]# tar-zxf phpMyAdmin-4.7.0-all-languages.tar.gz -C /var/www/html/
]# cd /var/www/html
]# mv phpMyAdmin-4.7.0-all-languages phpMyAdmin //改变目录名
]# chown -R apache:apache phpMyAdmin/
1.3 修改软件的配置文件定义管理的数据库服务器
]# cd phpMyAdmin
phpMyAdmin]# cp config.sample.inc.php config.inc.php
//备份主配置文件
phpMyAdmin]# vim config.inc.php //编辑主配置文件
17 $cfg[‘blowfish_secret‘] = ‘zk123‘; //给cookie做认证的值,可以随便填写
31 $cfg[‘Servers‘][$i][‘host‘] =‘localhost‘; //指定主机名,定义连接哪台服务器
浏览器输入:http://192.168.4.20/phpMyAdmin/
用户名是root,密码是123456 可视化操作数据库
2.密码恢复及设置
恢复MySQL管理列表
正常设置管理密码
2.1 恢复密码
]# systemctl stop mysqld.service
]# systemctl status mysqld.service
]# vim /etc/my.cnf
[mysqld]
skip_grant_tables=1
...
]# systemctl restart mysqld.service
]# systemctl status mysqld.service
]# mysql -u root (直接进入)
mysql> UPDATE mysql.user SET authentication_string=PASSWORD(‘1234567‘)
-> WHERE user=‘root‘ AND host=‘localhost‘; //重设root的密码
mysql> FLUSH PRIVILEGES; //刷新授权表
]# vim /etc/my.cnf
[mysqld]
#skip_grant_tables=1
]# systemctl restart mysqld.service
重新登陆即可
2.2 正常设置MySQL管理密码
方法1,在Shell命令行下设置
使用mysqladmin管理工具,需要验证旧的密码。比如,以下操作将会把root的密码设置为 123456:
]# mysqladmin -u root -p password ‘123456‘
Enter password: //验证原来的密码
方法2
mysql> SET PASSWORD FOR [email protected]=PASSWORD(‘1234567‘);
方法3
mysql> GRANT all ON *.* TO [email protected] IDENTIFIED BY ‘1234567‘;
方法4
mysql> UPDATE mysql.user SET authentication_string=PASSWORD(‘1234567‘)
-> WHERE user=‘root‘ AND host=‘localhost‘; //重设root的密码
3.用户授权及撤销
3.1 192.168.4.20授权
mysql> GRANT all ON *.* TO [email protected]‘192.168.4.%‘ IDENTIFIED BY ‘1234567‘;
192.168.4.21登陆:
]# mysql -h 192.168.4.20 -uroot -p1234567
3.2 授权时,赋予授权权限
mysql> GRANT all ON *.* TO [email protected](仅本地可登)
-> IDENTIFIED BY ‘1234567‘
-> WITH GRANT OPTION;
查看授权:
mysql> SHOW GRANTS FOR [email protected];
3.3 撤销root用户的授权
mysql> REVOKE all ON *.* FROM [email protected];
解决办法:从其他超级权限用户登陆
mysql> GRANT all ON *.* TO [email protected] IDENTIFIED BY ‘123456‘;
3.4 允许webuser从任意客户机登录,只对webdb库有完全权限,密码为 888888
mysql> GRANT all ON webdb.* TO [email protected]‘%‘ IDENTIFIED BY ‘888888‘;
撤销webuser的完全权限,改为查询权限
mysql> REVOKE all ON webdb.* FROM [email protected]‘%‘;
只赋予查询权限:
mysql> GRANT select ON webdb.* TO [email protected]‘%‘;
确认授权更改结果
mysql> SHOW GRANTS FOR [email protected]‘%‘;
--------------------------------------------
| Grants for [email protected]% |
--------------------------------------------
| GRANT USAGE ON *.* TO ‘webuser‘@‘%‘ |
| GRANT SELECT ON `webdb`.* TO ‘webuser‘@‘%‘ |
--------------------------------------------