1. 下载mysql的repo源
$?wget?http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2. 安装mysql-community-release-el7-5.noarch.rpm包
$?sudo?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。
3. 安装mysql
$?sudo?yum?install?mysql-server
根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。
4. 重置密码
重置密码前,首先要登录
$?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的拥有者改为当前用户:
$?sudo?chown?-R?openscanner:openscanner?/var/lib/mysql
然后,重启服务:
$?service?mysqld?restart
接下来登录重置密码:
$?mysql?-u?root
mysql?>?use?mysql; mysql?>?update?user?set?password=password(‘123456‘)?where?user=‘root‘; mysql?>?exit;
5. 开放3306端口
$?sudo?vim?/etc/sysconfig/iptables
添加以下内容:
-A?INPUT?-p?tcp?-m?state?--state?NEW?-m?tcp?--dport?3306?-j?ACCEPT
保存后重启防火墙:
$?sudo?service?iptables?restart
这样从其它客户机也可以连接上mysql服务了。
允许指定ip可以连接数据库
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO?‘root’@’192.168.1.3’?IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
flush privileges;
本文链接地址: centos7下使用yum安装mysql