linux安装mysql5.7.33

  • Post author:
  • Post category:linux




linux安装mysql5.7.33

mysql 5.7.33 下载地址


mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz

# 下载mysql二进制包资源放到/usr/local/src下
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz



#进入到/usr/local/src目录下
cd /usr/local/src

#解压
tar zxvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz

#添加用户组
groupadd -r mysql
useradd -r -g mysql -s /bin/false -M mysql

#移动相关目录,并创建数据存放目录
mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /usr/local/mysql/data

#配置环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

#授权
chown -R mysql:mysql /usr/local/mysql/

#修改mysql默认配置文件
vim /etc/my.cnf

#在其中添加以下内容
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
log-error=/usr/local/mysql/data/mysqld.err
socket=/tmp/mysql.sock

#初始化
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#复制相关配置文件实现开机自启
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
service mysqld start

#获取安装时的临时密码
grep password /usr/local/mysql/data/mysqld.err

在这里插入图片描述


#使用临时密码登录
mysql -uroot -p临时密码

#登陆成功修改root用户登录密码
alter user root@localhost identified by '123456'

#开启远程链接
use mysql;
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;



linux重置mysql密码

1.先停掉MySQL的服务

service mysqld stop

2.使用安全模式登陆,跳过密码验证

mysqld_safe --user=mysql --skip-grant-tables --skip-networking&

3.登陆

mysql -uroot  mysql

4.修改密码 password括号内是要设置的密码

update user set authentication_string = password('123456') where user = 'root' and Host = 'localhost'

5.刷新权限

flush privileges;

6.重新使用正常模式登陆

mysql -uroot -p
enter password : 123456

可以正常登陆。

7.执行其他命令:show databases; 提示如下错误

You must reset your password using ALTER USER statement before executing this statement.

8.重新将密码设置一遍即可

set password = password (‘123456’);



版权声明:本文为a654540233原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。