赞
踩
下载对应版本:MySQL :: Download MySQL Community Server
下载好之后把安装包上传到服务器自己的位置,我的是:/usr/local/mysql
1.解压前先通过命令查看一下是不是由其他数据库存在,我们要删除mariadb数据库
- //查找mariadb数据库
- rpm -qa | grep mariadb
- //删除它
- rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
2.开始解压:
进入到MySQL安装包的目录下,比如我的是:/usr/local/mysql
- //解压MySQL安装包,根据自己的改一下名称
- tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar
3.开始下载:
它这个里面会有很多,我们只需要下载对我们有用的:
mysql-community-common
mysql-community-libs
mysql-community-client
mysql-community-server
对应命令:
- rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm --nodeps --force
如果跟我是一个版本8.0.26可以直接复制一次性运行,也可以自己对应自己的
执行情况如下:
如果不放心是否安装正确可以运行下面命令确定一下:
rpm -qa | grep mysql
因为后面咱们需要链接数据库,并在代码中成功测试,所以有两种配置方式:
- # 通过vi命令编辑my.cnf配置文件
- vi /etc/my.cnf
- # For advice on how to change settings please see
- # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
-
- [mysqld]
- #skip-grant-tables
- #
- # Remove leading # and set to the amount of RAM for the most important data
- # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
- # innodb_buffer_pool_size = 128M
- #
- # Remove the leading "# " to disable binary logging
- # Binary logging captures changes between backups and is enabled by
- # default. It's default setting is log_bin=binlog
- # disable_log_bin
- #
- # Remove leading # to set options mainly useful for reporting servers.
- # The server defaults are faster for transactions and fast SELECTs.
- # Adjust sizes as needed, experiment to find the optimal values.
- # join_buffer_size = 128M
- # sort_buffer_size = 2M
- # read_rnd_buffer_size = 2M
- #
- # Remove leading # to revert to previous value for default_authentication_plugin,
- # this will increase compatibility with older clients. For background, see:
- # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
- # default-authentication-plugin=mysql_native_password
-
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
-
- bind-address = ifconfig获取到的地址
-
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
-
- # 忽略表名大小写
- lower_case_table_names=1
返回到服务器跟目录:
- mysqld --initialize
- chown mysql:mysql /var/lib/mysql -R
- systemctl start mysqld.service
- systemctl enable mysqld
- //查看root用户初始化的密码
- cat /var/log/mysqld.log | grep password
- //使用密码登录
- mysql -u root -p
修改root密码:
alter user "root"@"localhost" identified by "你自己的密码";
- create user 'root'@'%' identified with mysql_native_password by '刚才设置的密码';
- grant all privileges on *.* to 'root'@'%' with grant option;
- flush privileges; --立即生效
- ALTER USER 'root'@'localhost' IDENTIFIED BY '数据库密码' PASSWORD EXPIRE NEVER;
- flush privileges;
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
- firewall-cmd --reload
防火墙基本操作命令如下:
- systemctl start firewalld.service # 启动防火墙
- systemctl stop firewalld.service # 停止运行防火墙
- systemctl status firewalld.service # 查看防火墙状态
- systemctl restart firewalld.service # 重启防火墙
- systemctl disable firewalld.service # 禁止开机启动
- systemctl mask firewalld.service # 注销防火墙
步骤:登录进去--》控制台--》控制台--》安全组--》管理规则--》手动添加
优先级是:1~100(1是最高);端口范围:里面选择MySQL就好;描述:看你心情想写就写
主机:服务器公网IP(jdbc中也是公网IP哦)
地址就是,你配置的公网IP
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。