- 下载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。
- 安装mysql
$ sudo 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的拥有者改为当前用户:
$ sudo chown -R openscanner:openscanner /var/lib/mysql
然后,重启服务:
$ service mysqld restart
接下来登录重置密码:
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘1234’) where user=‘root’;
- 需要更改权限才能实现远程连接MYSQL数据库
mysql> use mysql; (此DB存放MySQL的各种配置信息)
mysql> select host,user from user; (查看用户的权限情况)
mysql> select host, user, password from user;
由此可以看出,只能以localhost的主机方式访问。
解决方法:
mysql> Grant all privileges on . to ‘root’@’%’ identified by ‘1234’ with grant option;
mysql> flush privileges;
再次查看。。
mysql> select host, user, password from user;
添加端口3306到防火墙规则中,同时重启防火墙
命令
1.启动MySQL服务
systemctl start mysqld
2.重启
systemctl restart mysqld
3.查看MySQL的启动状态
systemctl status mysqld
4.开机启动
systemctl enable mysqld
systemctl daemon-reload