Linux系统Mysql下载安装配置

  Linux系统Mysql下载安装配置

#清除环境

  1. 查看是否存在mysql用户的命令:
    cat /etc/group | grep mysql
    cat /etc/passwd |grep mysql
  2. 增加 mysql 用户的命令:
    groupadd mysql
    useradd -r -g mysql mysql

1下载安装包

 Mysql官网:MySQL :: Download MySQL Community Server (Archived Versions)icon-default.png?t=N7T8https://downloads.mysql.com/archives/community/

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz   #java21版本
2、解压缩

tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql

3、所属组

chmod -R 755 /usr/local/mysql
mkdir -p /data/mysql #创建目录
chown mysql:mysql -R /data/mysql #网上的 赋予权限
chmod 777 /data/mysql #自己给赋的权

4、主配置文件

/etc/my.cnf

[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
bind-address=127.0.0.1
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
#socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
##character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/data/mysql/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
pid-file=/data/mysql/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d


5、初始化

./mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
查看密码 cat /data/mysql/mysql.err

 

 
6、服务启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
ps -ef|grep mysql

ln -s  /usr/local/mysql/bin/* /usr/local/bin/

7、登录

mysql -u root -p
SET PASSWORD = PASSWORD('Qwertyuiop1');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
或执行命令:set password for root@localhost = password('Qwertyuiop1');
FLUSH PRIVILEGES;

8、开启远程连接功能

use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;

9、windows连接登录

[root@localhost bin]# vim /etc/my.cnf

bind-address=0.0.0.0    #修改此ip

[root@localhost bin]# service mysql restart

Shutting down MySQL.... SUCCESS!

Starting MySQL. SUCCESS!

[root@localhost bin]# netstat -ntlp           

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      12267/mysqld        

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1018/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1203/master         

tcp6       0      0 :::22                   :::*                    LISTEN      1018/sshd           

tcp6       0      0 ::1:25                  :::*                    LISTEN      1203/master      

原文:  https://www.cnblogs.com/qinshizhishi/p/13828150.html 

             Linux下安装Mysql为什么要创建对应的用户和用户组? - 掘金 (juejin.cn)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SilentCodeY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值