您现在的位置是:首页 > 技术博客 > linux_centos7_安装mysql8.0.15

linux_centos7_安装mysql8.0.15

2021-06-21文远技术博客980311

本文介绍的是在linux centos7下安装mysql8.0.15

一、获取mysql

可以官网下载

或者使用我 提供好的

https://pan.baidu.com/s/1LVUau71wSmaE84QTuEDSFQ

提取码:7mr9

也可以使用wget命令下载,不过下载的太慢了

 

这是一个xz包,先用xz命令解压成tar包,再用tar命令解压成文件夹,可能会有点慢,因为文件有点大,估计在1.8GB左右

[root@VM-0-15-centos ~]# xz -d mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
[root@VM-0-15-centos ~]# tar xf mysql-8.0.15-linux-glibc2.12-x86_64.tar
[root@VM-0-15-centos ~]# cd mysql-8.0.15-linux-glibc2.12-x86_64

linux_centos7_安装mysql8.0.15

解压工作完成,进入mysql文件夹,可以看见mysql的文件目录

二、安装

 我们把解压好的mysql文件夹移动到/usr/local/mysql,这个目录可以自己定义

安装完成

三、配置mysql

修改配置文件my.cnf

我这里提供了一份比较详细的配置文件

https://pan.baidu.com/s/1matQzLm5FvPmJzi8LMV_Ng

提取码:6t23

可以使用ftp把 /etc下的my.cnf文件替换掉

替换完之后,我们需要创建几个目录,具体的路径在my.cnf里面,这里跟着我直接创建目录就行了

#切记,创建目录的时候,一定要在mysql文件的根目录创建
[root@VM-0-15-centos mysql]# mkdir data sql_log undo [root@VM-0-15-centos mysql]#

创建一个mysql账号用来启动mysql服务,一般不用root账号,这样不安全

[root@VM-0-15-centos mysql]# adduser mysql

把mysql目录更创建的文件的属、组改变成mysql的

[root@VM-0-15-centos mysql]# chown mysql:mysql -R data/ sql_log/ undo/

四、初始化mysql

添加mysql全局环境变量

#在最后加上export PATH=$PATH:/usr/local/mysql/bin
#/usr/local/mysql是你的mysql安装目录
#:wq保存退出
[root@VM-0-15-centos mysql]# vi /etc/profile
#重新加载环境变量
[root@VM-0-15-centos mysql]# source /etc/profile

初始化mysql,在5.7以后的版本需要用mysqld命令

[root@VM-0-15-centos mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

--user 指定mysql用户
--basedir 指定安装目录
--datadir 指定日志目录

初始化后可以进入data目录,会发现自动生成了系统的数据库

 

进行下一步,把启动脚本放到启动目录

我们先进入到mysql根目录下的support-files目录

[root@VM-0-15-centos mysql]# cd support-files
[root@VM-0-15-centos support-files]# cp mysql.server /etc/init.d/mysql

启动mysql

#启动
[root@VM-0-15-centos support-files]# /etc/init.d/mysql start

#停止
[root@VM-0-15-centos support-files]# /etc/init.d/mysql stop

#重启
[root@VM-0-15-centos support-files]# /etc/init.d/mysql restart

#查看mysql进程
[root@VM-0-15-centos support-files]# ps -ef|grep mysql

看见这样的提示就说明启动成功了

Starting MySQL... SUCCESS!

五、登录mysql

获取默认密码

在mysql根目录下的sql_log目录下有mysql的日志文件mysql_error.log

执行如下命令

[root@VM-0-15-centos sql_log]# grep password mysql-error.log

会得到类似的字符串

2021-01-07T02:31:11.723844Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: .utdq=g)E6!Z

root@localhost: 后面的就是密码。账号就是root

[root@VM-0-15-centos sql_log]# mysql -uroot -p

输入默认密码。登录成功

可能会有人提示 mysql的密码已经过期,这样的话你可以进行如下操作,进行免密码登录

 点击这里查看如何进行免密码登录

文章评论

看完文章了吗?谁便说点吧

发表 captcha
游客_1627267425 2021-07-26 10:43:45
<h1>This is a test</h1>