TypechoJoeTheme

IT技术分享

统计

Linux CentOS 7 下安装MySQL并配置远程访问

2016-08-25
/
0 评论
/
734 阅读
/
正在检测是否收录...
08/25

一、下载mysql的repo源

下载地址:MySQL下载页
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

二、安装相应包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

三、 安装mysql

yum install mysql-server

四、重置密码

mysql -u root

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:

chown -R root:root /var/lib/mysql

然后,重启服务:

service mysqld restart

接下来登录重置密码:

mysql -u root
use mysql;
update user set password=password('password') where user=‘root‘;
flush privileges;  
quit;
service mysqld restart;

五、开放3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
如果出现FirewallD is not running, 请先启动firewall
systemctl start firewalld

六、允许远程访问

进入mysql后

GRANT ALL ON *.* TO root@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;
quit;
service mysqld restart

七、创建用户并允许远程和本地访问

grant all on dbname.* to 'user1'@'%' identified by 'password';
grant all on dbname.* to 'user1'@'localhost' identified by 'password';
exit;
service mysqld restart
朗读
赞 · 0
版权属于:

IT技术分享

本文链接:

https://idunso.com/archives/2298/(转载时请注明本文出处及文章链接)