vlambda博客
学习文章列表

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=3336basedir=/home/grnleaf/mysqldatadir=/home/grnleaf/mysql/datapid-file=/home/grnleaf/mysql/mysql.pidsocket=/home/grnleaf/mysql/mysql.socklog_error=/home/grnleaf/mysql/error.logserver-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.log2021-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密码

mysql> alter user 'root'@'localhost' identified by '123456';mysql> flush privileges;


完成!