官网下载https://dev.mysql.com/downloads/mysql/,本文安装包mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar
安装步骤
1、在usr/local/mysql文件夹下,通过Xftp6上传mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar文件,使用命令:tar -xvf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar,解压文件到当前目录下
2、安装顺序依次为common->libs->client->server
安装common命令:rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm --nodeps --force
安装libs命令:rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm --nodeps --force
安装client命令:rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm --nodeps --force
安装server命令:rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --nodeps --force
3、通过rpm -qa | grep mysql命令查看mysql的安装包
4、mysql数据库初始化和相关配置
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
启动防火墙
systemctl start mysqld.service
systemctl enable mysqld
5、通过cat /var/log/mysqld.log | grep password命令查看数据库随机生成的密码
初始密码为:w%l5hNFiap>K
6、mysql -uroot -p登录数据库
7、修改密码命令:ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’; 操作完成后刷新MySQL的系统权限命令:FLUSH PRIVILEGES;
8、远程访问的授权命令
create user '用户名'@'主机' identified with mysql_native_password by '密码';
grant all privileges on *.* to '用户名'@'主机';
grant all privileges on *.* to '用户名'@'%' with grant option
grant select,insert,update,delete,create,drop,alert on *.* to '用户名'@'密码';
flush privileges;
show grants for '用户名'@'主机';
9、通过以下命令,关闭 firewall
systemctl stop firewalld.service;
systemctl disable firewalld.service;
systemctl mask firewalld.service;
10、通过yum -y install iptables-services命令安装iptables防火墙
15、通过vim /etc/sysconfig/iptables命令编辑防火墙,添加以下端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8090 -j ACCEPT
……
16、systemctl restart iptables.service命令重启防火墙使配置生效
17、systemctl enable iptables.service命令设置防火墙开机启动
mysql-8.0.18添加用户全步骤
1、先创建用户
create user ‘用户名’@‘主机’ identified by ‘password’;
例如:create user 'abc'@'%' identified by 'abc123456';(亲测使用)
2、授权所有权限
grant all privileges on *.* to '用户名'@'主机';
例如:grant all privileges on *.* to 'abc'@'%'; (亲测使用)
3、刷新权限
flush privileges;
授权Navicat for MySQL工具管理MySQL
命令:ALTER USER ‘用户名’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘密码’;
修改完成,刷新MySQL的系统权限命令:FLUSH PRIVILEGES;
至此,MySQL数据库就可以成功连接Navicat for MySQL工具