Mysql简易安装指南

1. Mysql数据库安装:

MySQL常见的安装方式有三种,一种是yum/rpm安装,一种是二进制源码包安装,还有一种是源码编译安装。

1.1 yum部署:

Yum 安装方法很简单,执行命令如下即可:

### Centos 7默认是安装mariadb 5.5,由base源提供,不需要配置其他源:
# 安装:
yum install –y  mariadb  mariadb-devel  mariadb-server
# 启动:
[root@localhost ~]# systemctl  start  mariadb
# 连接:
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 


### 如果想安装MySQL版本,可以单独配置MySQL仓库(这里是用的清华源,如果直接配置MySQL的外网源速度很慢):
# 配置MySQL的秘钥:
yum install -y https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql80-community-release-el7-3.noarch.rpm
# 移除外网源:
mv /etc/yum.repos.d/mysql-* /tmp/
# 配置国内源:
cat > /etc/yum.repos.d/mysql.repo <<EOF
[mysql]
name=centos 7 mysql repo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
# 安装:
yum install  mysql mysql-server -y

# 启动:
[root@localhost ~]# systemctl start mysqld
# 连接(用初始密码连接):
[root@localhost ~]# mysql -p'gflm7PSk#&zR'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.25

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>
1.2 二进制部署:
# 下载二进制包:
wget  -c  https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.24-el7-x86_64.tar.gz

# 解压缩:
[root@localhost src]# tar xf mysql-8.0.24-el7-x86_64.tar.gz 
[root@localhost src]# mv mysql-8.0.24-el7-x86_64 /usr/local/mysql
[root@localhost src]# cd /usr/local/mysql/

# 准备脚本文件:
[root@localhost mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
# 准备配置文件:
[root@localhost mysql]# cat > my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/
port=3306
pid-file=/data/mysql/mysql.pid
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/data/mysql/mysql.log
EOF

# 创建数据目录:
[root@localhost mysql]# mkdir -p /data/mysql
[root@localhost mysql]# chown mysql. /data/mysql

# 无密码初始化:
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
# 有密码初始化:
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

# 启动:
[root@localhost mysql]# /etc/init.d/mysqld start

# 登录:
[root@localhost mysql]# usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.24 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
1.3 源码编译部署:
# 安装依赖:
yum install gcc ncurses-devel libaio bison gcc-c++  git cmake   openssl-devel -y

wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar xf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boost

wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
tar xf  mysql-5.7.28.tar.gz
cd mysql-5.7.28

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/usr/local/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0 \
-DENABLE_DTRACE=0 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost

make && make install

mkdir -p /data/mysql
useradd -s /sbin/nologin mysql
chown -R mysql. /data/mysql

cp support-files/mysql.server /etc/init.d/mysqld
chmod +x  /etc/init.d/mysqld

cat >  /usr/local/mysql/my.cnf  <<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
pid-file=/data/mysql/mysql.pid
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/data/mysql/mysql.log

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

# 启动:
/etc/init.d/mysqld start

获取文章更新,以及常用软件,可以关注公众号: 笨办法学linux

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

运维朱工

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

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

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

打赏作者

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

抵扣说明:

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

余额充值