1.安装wget
sudo yum install wget
2.下载安装包
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
3.安装
sudo rpm -ivh mysql57-community-release-el7-8.noarch.rpm
sudo yum install mysql-server
4.启动mysq服务
systemctl start mysqld
5.配置mysql安装项
sudo mysql_secure_installation
输入两遍新密码 剩余的一般我们都输入y,
(是否安装密码安全插件,开发环境可以选n)
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
(安全模式0低,1中等,2强)
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
(是否删除匿名用户)
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
(是否禁止root远程登录)
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
(是否删除测试数据库)
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
(是否重新加载权限)
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
出现All done 证明配置完成
6.检查mysql服务
//查看进程:
ps -ef|grep mysql
//启动服务:
service mysql start
//停止服务:
service mysql stop
//重启服务:
service mysql restart
7.配置防火墙
//查看防火墙状态
systemctl status firewalld
//查看已经开放的端口
firewall-cmd --list-ports
//开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//重新载入
firewall-cmd --reload
8.Mysql对外开放 允许被远程连接访问
1、更改 mysql 数据库里 user 表里的 host 项(列),把 localhost 改为 %。
或者新加条新的记录,host 列的值为要访问的ip地址,并授权。重启mysql服务。
可能用到的命令:
//登录mysql
mysql -u root -p
//mysql中 查看所有数据库
show databases;
//选择名为mysql的库
use mysql;
//查看表
show tables;
//sql语句 更改权限
select host from user where user='root';
update user set host = '%' where user = 'root';
//重启mysql服务
systemctl restart mysqld
9.如果是腾讯云、阿里云等云服务器需要在控制台开放服务器防火墙端口
10.外部连接
使用navicat连接
大功告成
11.卸载mysql数据库(没试过)
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt autoclean