Centos7 安装 mysql8超详细流程(逐步介绍)

首先,感谢 “https://blog.****.net/weixin_38898423/article/details/103473895” 给我的指导。

本文是基于上述博客,再加了一些细节写成!!!!!

--- 干货如下 ------>

1 到mysql官网下载符合系统版本的sql8的包(具体怎么下百度一下,我是别人给了一个):

        我们服务器是Centos 7.7,下载的包为:mysql-8.0.19-el7-x86_64.tar.gz

2 将该包传到服务器上(怎么传这个不介绍了,我用的FileZilla):

        比如我就传到了服务器上的:/workspace/software_package/mysql-8.0.19-el7-x86_64.tar.gz

3 cd到这个包的目录下,将其解压:

        [[email protected] software_package] tar -zxvf mysql-8.0.19-el7-x86_64.tar.gz

4 将解压后的文件夹移动到/usr/local下:

        mv /workspace/software_package/mysql-8.0.19-el7-x86_64  /usr/local/

5 cd到/usr/local下,将其改名为mysql: mv mysql-8.0.19-el7-x86_64 mysql

        Centos7 安装 mysql8超详细流程(逐步介绍)

6 在/usr/local下,创建用户和用户组并授权:

[[email protected] local]# groupadd mysql

[[email protected] local]# useradd -r -g mysql mysql

[[email protected] local]# chown -R mysql:mysql ./   #授权

7 cd到mysql下,创建data文件夹:

[[email protected] mysql]# mkdir data

8 开始初始化数据库,运行下面这段后,记得记下初始化的密码:

[[email protected] mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Centos7 安装 mysql8超详细流程(逐步介绍)

10 还是在mysql下,修改当前用户的目录:

[[email protected] mysql]# chown -R root:root ./

[[email protected] mysql]# chown -R mysql:mysql data

11 开始创建配置文件 my.cnf:

[[email protected] mysql]# cd support-files/

[[email protected] support-files]# touch my-default.cnf

[[email protected] support-files]# chmod 777 ./my-default.cnf

[[email protected] support-files]# cp support-files/my-default.cnf /etc/my.cnf

cp: 无法获取"support-files/my-default.cnf" 的文件状态(stat): 没有那个文件或目录

[[email protected] support-files]# cp my-default.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? yes

12 上面这一步我执行了,但没有什么东西,所以可能 my_cnf 还是为空,需要配置,同事建议我配置的是如下:

[[email protected] support-files]# vim /etc/my.cnf

        vim后里边内容写下边这段即可,完事后 cat /etc/my.cnf 检查一下:

[mysqld]

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

socket = /tmp/mysql.sock

            Centos7 安装 mysql8超详细流程(逐步介绍)

13 设置mysql开机自启动:

[[email protected] support-files]# cp mysql.server /etc/init.d/mysql

[[email protected] support-files]# chmod +x /etc/init.d/mysql

14 设置注册服务:

[[email protected] support-files]# chkconfig --add mysql

[[email protected] support-files]# chkconfig --list mysql

15 有的需要配置一下etc/ld.so.conf,不然要报错。如下:

[[email protected] support-files]# vim /etc/ld.so.conf

        vim后在最后添加一行即可:/usr/local/mysql/lib

         Centos7 安装 mysql8超详细流程(逐步介绍)

16  配置mysql环境变量:

[[email protected] support-files]# vim /etc/profile

       vim后,需要在该文件最后添加两行:

#MYSQL ENVIRONMENT

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysqlb

Centos7 安装 mysql8超详细流程(逐步介绍)

17 更新环境变量 (让前面的所有改动都生效)

[[email protected] support-files]# source /etc/profile

18 开始启动mysql(如果报错,可以回去检查一下那个 my.cnf):

[[email protected] ~]# service mysql start

19 开始登陆root用户的mysql:

[[email protected] local]# mysql -u root –p

这里会让输入密码,输入密码则为刚前面生成的那个即可:******,顺利的话就登录进去了哟!

Centos7 安装 mysql8超详细流程(逐步介绍)

20 首次登陆,记得修改密码:

mysql> alter user 'root'@'localhost' identified by '修改后的密码';

        注意:如果需要将权限放大到任何外部ip都能访问,则把localhost改为%, 后面同理!

21 为mysql新增一个登陆用户,并为之赋权:

mysql> CREATE USER 'test_user'@'%' IDENTIFIED BY '新增用户的密码';

mysql> GRANT ALL ON *.* TO 'test_user'@'%';

22 如何新增一个数据库和显示当前所有数据库:

mysql> create database testdb; 

mysql> show databases;

Centos7 安装 mysql8超详细流程(逐步介绍)

22 修改密码规则(这一步,貌似可以解决终端能登mysql而其他设备不能等mysql的问题):

mysql> ALTER USER 'test_user'@'%' IDENTIFIED WITH mysql_native_password BY '新的密码';

mysql> ALTER USER 'test_user'@'%' IDENTIFIED BY '新的密码' PASSWORD EXPIRE NEVER;

23 退出root登陆,改为创建的用户来登录看看:

mysql -u test_user –p, 密码为你新改的密码