admin管理员组

文章数量:1605606

文章目录

  • 安装MySQL 5.6.46
    • 选择包
    • 下载包
    • 解压
    • 重命名
    • MySQL配置操作
      • 1. 进入到mysql目录,执行添加MySQL配置的操作
      • 2. 编辑/etc/myf文件
    • 创建mysql用户组及用户
    • 在mysql当前目录下设定目录的访问权限
    • 初始化数据
    • 初始化 MySQL
    • 启动mysql
    • 关闭服务
    • 设置开机启动
    • 启动mysql服务
    • 查看mysql状态
  • 安装MySQL 8.0.25
    • 下载包
    • 解压
    • 重命名
    • 权限设置
    • 配置文件
      • 官方指南
    • 初始化mysql
    • 启动mysql
      • 普通启动
      • 安装成服务启动
    • 测试登录及修改密码
    • 关闭服务
    • 创建开机自启动mysql服务

本篇文章总结如何在阿里云上安装MySQL数据库。

安装MySQL 5.6.46

选择包

从MySQL官网上下载MySQL包。这里选取5.6.46的版本。
https://downloads.mysql/archives/community/

在Download 按钮上,鼠标右键,复制链接。

切记,一定要下载对应机器位数的包,Linux是64位,就下载64位的包。

下载包

在Linux中,使用wget命令下载包。

wget 命令用来从指定的URL下载文件,wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。

如果没有安装,那么我们就用yum来安装wget:切换到root用户,在命令行中输入yum -y install wget
让它自己安装就可以了 -y 是为了让我们减少输入yes

下载包步骤:

cd /opt/

wget https://downloads.mysql/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz --user-agent="Mozilla/5.0 (X11;U;Linux i686;en-US;rv:1.9.0.3) Geco/2008092416 Firefox/3.0.3" --no-check-certificate

解压

tar -xzv -f mysql-5.6.46-linux-glibc2.12-i686.tar.gz

重命名

mv mysql-5.6.46-linux-glibc2.12-i686 mysql-5.6.46

MySQL配置操作

1. 进入到mysql目录,执行添加MySQL配置的操作

cp support-files/my-defaultf /etc/myf

2. 编辑/etc/myf文件

vi /etc/myf

添加下面的内容:

# For advice on how to change settings please see
# http://dev.mysql/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir =/opt/mysql-5.6.46
datadir = /opt/mysql-5.6.46/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /opt/mysql-5.6.46/data/error.log
pid-file =/opt/mysql-5.6.46/data/mysql.pid

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

创建mysql用户组及用户

groupadd mysql
useradd -r -s /usr/sbin/nologin -g mysql mysql -d /opt/mysql-5.6.46

当然这里也可以强制使用root 账号运行,运行时加上参数--user=root,就可以不用做下面的访问权限设置了。

在mysql当前目录下设定目录的访问权限

注意后面的小点,表示当前目录

chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data

初始化数据

在mysql/bin 或者 mysql/scripts下有个mysql_install_db可执行文件初始化数据库,进入mysql/bin或者mysql/scripts目录下,执行下面命令:

./mysql_install_db --verbose --user=root --defaults-file=/etc/myf --datadir=/opt/mysql-5.6.46/data --basedir=/opt/mysql-5.6.46 --pid-file=/opt/mysql-5.6.46/data/mysql.pid --tmpdir=/tmp

5.7.x之后的版本初始化数据库不再使用mysql_install_db,

本文标签: 版本系统CommunitymysqlLinux