Centos7中搭建MySQL环境

  • 1、 安装社区套件yum源地址:
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  • 2、安装MySQL服务:
yum -y install mysql-community-server
  • 3、把/var/lib/mysql的拥有者改为当前用户:
chown -R mysql:mysql /var/lib/mysql
  • 4、重启MySQL:
systemctl restart mysql
  • 5、以root用户身份登陆MySQL:
mysql -u root
  • 6、使用mysql数据库:
use mysql;
  • 7、重置MySQL密码:(新密码为:new-password)
update user set password = 'new-password' where user = 'root';
  • 8、查看用户的权限情况:
select host,user,password from user;
  • 9、将MySQL使可以外部连接:(new-password为你刚刚设置的密码)
Grant all privileges on *.* to 'root'@'%' identified by 'new-password' with grant option;

使用:

mysql> select host,user,password from user;

可以看见表中多了一行被加密的数据
host=%,user=root,password=*4A82FDF1D80BA7470BA2E17FEEFD5A53D5D3B762

  • 10、开放数据库的3306默认端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent		#永久开放3306端口
  • 此时就可以从外部连接MySQL了

如您在阅读中发现不足,欢迎留言!!!

发布了63 篇原创文章 · 获赞 66 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40065776/article/details/101000334