Linux系统下搭建mysql服务器精粹!精心总结记录下操作过程

一、环境准备
(1)下载Linux版本的mysql服务器,这里根据自己的需求下载相应的版本,作者这里下载的是
mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar
(2)查是否有旧版本的mysql包,有的centos镜像会默认携带,检查方式如下:rpm -qa | grep mariadb
[root@xhqHost xhqMysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
(3)有的话要删除,没有的话就可以跳过下面的步骤(本实例中有),再检查是否删除成功。
[root@xhqHost xhqMysql]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
[root@xhqHost xhqMysql]# rpm -qa|grep mariadb
(4)操作需要的软件及工具: SecureCRT或者WinSCP(此处使用这两个工具),Xshell或者PuTTy,Xftp或者FileZilla,
mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar,mysql的linux版软件
apache-tomcat-8.0.58.tar.gz
二、在Linux下安装mysql
1、创建目录
在linux系统的用户目录下创建安装mysql的目录,命令如下: cd usr/local mkdir -m 777 xhqMysql

注意:如果创建的文件夹没有读写权限,则需要授权: a.创建的时候授权:mkdir -m 777 myTomcat b.对已经创建好的文件夹授权:chmod -R 777 myTomcat
2、拷贝安装包
使用WinSCP软件将下载好的mysql安装包拷贝到刚创建好的目录下面

3、解压安装包
解压:tar -xvf
mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar

1、安装common
rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm --nodeps --force

2、安装libs
rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm --nodeps --force

3、安装client
rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm --nodeps --force

4、安装server
rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm --nodeps --force

5、查看已安装的mysql安装包
rpm -qa|grep mysql

6、对 mysql 数据库进行初始化和相关配置
mysqld --initialize; 初始化mysql
chown mysql:mysql /var/lib/mysql -R; 对操作文件赋予权限
systemctl start mysqld.service; 启动mysql服务
systemctl enable mysqld; 设置开机自启

7、查看生成的默认密码
cat /var/log/mysqld.log/|grep password

8、使用刚才查询到的密码登陆mysql并修改密码
mysql -uroot -p

9、修改mysql用户密码为root,然后退出
alter user 'root'@'localhost'identified with mysql_native_password by 'root'

10、新密码重新登录mysql,进行远程访问授权
(1)登陆:mysql -uroot -p

(2)授权:
create user 'root'@'%'identified with mysql_native_password by 'root'
grant all privileges on *.* to 'root'@'%'with grant option;
flush privileges
(3)退出mysql
到这里MySQL就安装完毕了,但是通常这时候远程访问还是访问不到的,因为系统防火墙还没有关闭,下面这个步骤可选,如果工作环境不允许关闭防火墙就需要单独为MySQL开启远程端口,将MySQL端口添加到防火墙白名单
一、防火墙配置
1、关闭防火墙
systemctl stop firewalld.service 停止防火墙
systemctl disable firewalld.service 禁用防火墙
systemctl mask firewalld.service 禁止开机自启
2、查看防火墙状态
systemctl status firewalld.service
相关推荐
-
「PHP」MVC框架是什么?为什么要用它2025-02-25 00:25:41
-
如何用PHP写一个比较安全的API系统(实现)2025-02-25 00:19:49
-
php 解析url获取相关信息2025-02-25 00:15:37
-
mysql命令总结和PyMysql2025-02-25 00:11:35
-
MySQL特性:深入理解ICP2025-02-25 00:11:07