Linux 安装Mysql5.6教程

1、下载mysql

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

mysql:5.6百度云盘链接:https://pan.baidu.com/s/1F_9_FNpW60htO6ojh8LX2g?pwd=ag22
提取码:ag22

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

groupadd mysql && useradd -r -g mysql mysql

3、上传解压,并初始化

#解压软件包并改名
tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.6.44-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/scripts/
./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql

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

–basedir指定Mysql安装目录

–datadir指定数据目录

–user所属用户

4、启动mysql

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

5、 修改密码

[root@bbb scripts]#  /usr/local/mysql/bin/mysql -u root
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> update mysql.user set Password=password('mysql') where Host='localhost' and User='root';
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,数据库)