Linux 安装Mysql5.7教程

1、下载mysql

选择对应的包 如下5.7包
下载官方 Mysql 包
https://downloads.mysql.com/archives/community/
Linux 安装Mysql5.7教程_第1张图片

mysql:5.7百度云盘链接:https://pan.baidu.com/s/1scj-iLFsTAJ9t-euWaJFFA?pwd=txjn
提取码:txjn

2、创建mysql用户组和mysql用户

groupadd mysql && useradd -r -g mysql mysql

3、上传解压,并初始化

#解压软件包并改名
tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
#创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
#修改配置文件
cat > /etc/my.cnf << EOF
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/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
EOF
#安装初始化依赖
yum -y install autoconf make perl
#执行初始化
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql  --initialize

其中:
–defaults-file 指定配置文件

–basedir指定Mysql安装目录

–datadir指定数据目录

–user所属用户

4、查看密码
cat /data/mysql/mysql.err
在这里插入图片描述

8、启动mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start

修改密码

[root@bbb bin]#  /usr/local/mysql/bin/mysql -uroot -p\(Jy3?#J+wvlM  #'('是特殊符号,所以加\去转义
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql> exit
Bye

你可能感兴趣的:(mysql,linux,mysql,服务器)