Centos非root用户二进制安装配置Mysql5.7.31
Posted GrnLeaf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos非root用户二进制安装配置Mysql5.7.31相关的知识,希望对你有一定的参考价值。
今天公司给了一个Centos7版本的普通用户让我安装mysql,我一上去想直接yum安装,结果想起我没有root密码不能用sudo,那么就用二进制的方法来吧!
以普通用户grnleaf为例
一、下载安装包
[grnleaf@localhost ~]$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
如果没有wget命令,请用yum安装(yum install -y wget)
二、解压缩包
[grnleaf@localhost ~]$ tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /home/grnleaf/
[grnleaf@localhost ~]$ mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
[grnleaf@localhost ~]$ vi /home/grnleaf/mysql/my.cnf
[client]
port=3336
socket=/home/grnleaf/mysql/mysql.sock
[mysqld]
port=3336
basedir=/home/grnleaf/mysql
datadir=/home/grnleaf/mysql/data
pid-file=/home/grnleaf/mysql/mysql.pid
socket=/home/grnleaf/mysql/mysql.sock
log_error=/home/grnleaf/mysql/error.log
server-id=100
三、设置环境变量
[grnleaf@localhost ~]$ echo 'export PATH=/home/grnleaf/mysql/bin:$PATH' /home/grnleaf/.bash_profile
[grnleaf@localhost ~]$ source /home/grnleaf/.bash_profile
四、安装mysql
[grnleaf@localhost ~]$ mysqld --defaults-file=/home/grnleaf/mysql/my.cnf --initialize --user=grnleaf --basedir=/home/grnleaf/mysql --datadir=/home/grnleaf/mysql/data
五、启动mysql
[grnleaf@localhost ~]$ mysqld_safe --defaults-file=/home/grnleaf/mysql/my.cnf --user=grnleaf &
六、登陆mysql
1、获取mysq初始密码
[grnleaf@localhost ~]$ grep password /home/grnleaf/mysql/error.log
2021-06-03T16:45:59.139057Z 1 [Note] A temporary password is generated for root@localhost: u:=NiCzED1#s
密码为u:=NiCzED1#s
2、使用sock启动mysql
[grnleaf@localhost ~]$ mysql -uroot -p -S /home/grnleaf/mysql/mysql.sock
3、修改mysql密码
'root'@'localhost' identified by '123456'; alter user
flush privileges;
完成!
以上是关于Centos非root用户二进制安装配置Mysql5.7.31的主要内容,如果未能解决你的问题,请参考以下文章