Centos7安装mysql5.7.36

LINUX 1分钟安装mysql5.7

  • 适用于centos7系统
    • 下载上传安装包
    • 开始安装
    • 启动
    • 登录
    • 配置环境变量
    • 设置开机自启

适用于centos7系统

下载上传安装包

官网地址https://downloads.mysql.com/archives/community/

开始安装

  1. 创建mysql用户

groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin

  1. 解压文件并改名

tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /data
mv mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz /data/mysql

  1. 创建 data文件

mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql

  1. 配置Mysql:/etc/my.cnf
[mysqld]
expire_logs_days = 10
basedir=/data/mysql
datadir=/data/mysql/data
port = 3306
socket=/tmp/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld/mysqld.pid
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
log-bin=mysql-bin
binlog-format=ROW
server_id=1
max_connections=5000
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
  1. 创建 sock、pid、log文件

touch /tmp/mysql.sock
mkdir -p /tmp/mysqld
touch /tmp/mysqld/mysqld.pid
touch /var/log/mysqld.log
chown mysql:mysql /tmp/mysql.sock
chown -R mysql:mysql /tmp/mysqld
chown -R mysql:mysql /var/log
chmod 755 /tmp/mysql.sock
chmod 755 /tmp/mysqld/mysqld.pid
chmod 755 /var/log/mysqld.log

  1. 安装Mysql

cd /data/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/data/mysql–datadir=/data/mysql/data
若报错:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
安装libaio:
yum install -y libaio
或者安装rpm包
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm
rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm

启动

  1. 安全启动:

./mysqld_safe --user=mysql &
默认密码在/var/log/mysqld.log日志里, 建议首次登录后修改密码:

登录

  1. 登录

进入mysql的bin目录:
cd /data/mysql/bin/
登录mysql:
./mysql -u root -p
mysql> set password=password(“123456”);
mysql>grant all privileges on . to ‘root’@‘%’ identified by ‘123456’;
mysql> flush privileges;

配置环境变量

  1. 在/etc/profile文件最后增加

export MYSQL_HOME=/data/mysql
export PATH=“$PATH:$MYSQL_HOME/bin”
立即生效
source /etc/profile

设置开机自启

  1. 重启并设置开机自启

cp -a /data/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld stop
service mysqld start
设置开机启动
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld on

Centos7安装mysql5.7.36_第1张图片

你可能感兴趣的:(mysql,数据库,服务器)