Linux安装MySQL5.7.26

欢迎关注微信公众号: 程序员小圈圈
原文首发于: www.zhangruibin.com
本文出自于: RebornChang的博客
转载请标明出处^_^

Linux安装MySQL5.7.26

清理环境

如果之前安装过MySQL的,重装需要清理之前下载的。

检查是否安装过

[root@localhost /]# rpm -qa | grep mysql

如果安装过的话会显示安装过的历史版本。

若是安装过则删除并且删除旧有的文件夹及MySQL用户

使用find和whereis找到文件或者文件夹rm删除,这里就不多说了。
如果之前没有安装过的话,直接跳过这一步然后看下面的就行了。

准备安装包

Linux安装MySQL首先要要准备安装包,安装包通用的分为两种方式
1.wget获取安装包


 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

2.官网下载压缩包
官网下载压缩包,然后上传到Linux上之后,解压安装。
可以自行官网下载,或者进入笔者公众号回复MySQL5.7即可获取下载链接。
3.将压缩包放到/usr/local/zhrb下
然后进行解压

[root@VM-0-10-centos zhrb]# ll
total 629760
-rw-r--r-- 1 root root 644869837 Oct 11 17:48 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@VM-0-10-centos zhrb]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

解压完毕之后,复制并修改文件夹名称为mysql-5.7.26

cp mysql-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql-5.7.26

此时,关于mysql资源已经准备完毕,接下来我们开始进行安装。

安装

新建用户

在/usr/local下执行

[root@VM-0-10-centos local]# groupadd mysql
[root@VM-0-10-centos local]# useradd -r -g mysql mysql

创建data文件夹用来存放mysql数据并分配权限

[root@VM-0-10-centos /]# mkdir -p data
[root@VM-0-10-centos /]# cd data/
[root@VM-0-10-centos data]# ll
[root@VM-0-10-centos data]# mkdir -p mysql
[root@VM-0-10-centos data]# chown mysql:mysql -R /data/mysql

修改my.cnf文件

[root@VM-0-10-centos data]# vim /etc/my.cnf

修改内容如下:

[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql-5.7.26
datadir=/data/mysql
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#绑定IP登录地址
#bind-address=0.0.0.0
socket=/var/lib/mysql/mysql.sock

#免密登录
#skip-grant-tables=1

注意免密登录这点,mysql在初始化安装的时候,会在mysql.err文件中打印初始root登录密码,如果需要直接密码登录的话就vi /data/mysql/mysql.err把密码复制出来,然后在/usr/local/mysql-5.7.26/bin目录下 mysql -u root -p 回车输入密码登录。
如果初始设置不想使用密码登录的话,就把skip-grant-tables=1的注释放开,输入密码时直接略过敲回车即可。

初始化mysql

切换到mysql的bin目录来进行初始化:

 [root@VM-0-10-centos data]# cd /usr/local/mysql-5.7.26/bin/
[root@VM-0-10-centos bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-5.7.26/ --datadir=/data/mysql/ --user=mysql --initialize
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

可以看到,初始化报错了,是因为缺少了一个库,那我们直接把这个库安装下就行了:

[root@VM-0-10-centos bin]# yum -y install numactl

安装过这个库之后,再进行初始化就没报错了。

然后看下初始化的root登录密码:

[root@VM-0-10-centos bin]# vim /data/mysql/mysql.err

如上面所说,可以使用免密登录,然后进去到mysql之后再修改root的密码。

启动mysql

[root@VM-0-10-centos bin]#  cd /usr/local/mysql-5.7.26/support-files
[root@VM-0-10-centos support-files]# ./mysql.server start
Starting MySQL SUCCESS! 

如上,成功启动mysql之后,我们登入mysql,进行root用户的密码修改。

修改root密码

如下,登录成功mysql之后,切换到mysql库,然后之后就可以对mysql的密码进行修改。

[root@VM-0-10-centos bin]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


修改root密码并且刷新权限

MySQL [mysql]> update mysql.user set authentication_string=password('password') where user='root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

MySQL [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MySQL [mysql]> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)


设置用户可以远程登录

MySQL [mysql]> update user set host = '%' where user = 'root';
MySQL [mysql]> update mysql.user set authentication_string=password('password') where user='root' and host = '%';

Query OK, 1 row affected (0.00 sec)
MySQL [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;
MySQL [mysql]> Flush Privileges;

在my.cnf文件中,bind-address=0.0.0.0注释掉。

至此,mysql-5.7.26已经安装成功了,如果按照 笔者这一套操作没有安装成功,有问题的话可以Google哈~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值