MySQL series-install MySQL

MySQL series-install MySQL

Operation and Maintenance YouthO&M Youth

Series of articles description

MySQL series articles include software installation, specific use, backup and recovery, etc., which are mainly used to record personal study notes. The main MySQL version used is 5.7.28, and the server system version is CentOS 7.5. This chapter is about software installation.

Download software

  • Open the official MySQL website (mysql.com)
  • Choose DOWNLOADS
  • Choose the community edition
    MySQL series-install MySQL

  • Choose the community version server
    MySQL series-install MySQL

下载说明
①该界面只能下载最新版本8.0.20

②如需下载历史版本,请选择Archives选项

③本系列笔记使用版本为5.7.28,故选择Archives

MySQL series-install MySQL

  • Select the corresponding software version, operating system version and other information, click Downloads (use Thunder download will be very fast)
    MySQL series-install MySQL

软件系统说明
①Product Version:软件版本

② Operating System:操作系统版本,Linux Gengric 为二进制版本,类似Windows中的绿色版,解压即用。

Preparation before installation

  • Check if mariadb is installed in the system, if it is installed, please uninstall it

rpm -qa | grep mariadb
yum remove mariadb-libs -y
  • Create new database users and groups

useradd mysql -s /sbin/nologin
  • Create related directories and modify permissions

mkdir -p /data/3306/     # 数据库数据目录
mkdir -p /app/database/  # 数据库软件目录
mkdir -p /binlog/3306/   # 数据库日志目录
chown -R mysql.mysql /app/ /data/ /binlog/  # 修改权限

install software

  • Upload software to /app/database
  • Unzip

tar -xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
  • The unzipped directory is longer, you can use ln to make a soft link, which is convenient for future use

 ln -s /app/database/mysql-5.7.28-linux-glibc2.12-x86_64 /app/database/mysql
  • Add the following line at the end of the /etc/profile file and source

export PATH=/app/database/mysql/bin:$PATH
  • Use the source command to reload the /etc/profile file

source /etc/profile
  • Use mysql -V to check whether the installation is successful

mysql -V

MySQL series-install MySQL

Initialize the database

  • Use the following command to initialize the database

mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/

initialize-insecure和initialize的区别
①initialize-insecure: 默认不为root设置密码,不自动设置密码复杂度

②initialize:默认设置一个临时密码,且开启密码复杂度要求

MySQL series-install MySQL

  • During initialization, if the following error is reported, it indicates that there are files in the database data directory, and the existing files need to be deleted and then initialized.
    MySQL series-install MySQL

Prepare configuration and startup script

  • Prepare my.cnf configuration script

cat > /etc/my.cnf << EOF
[mysqld]                    # 服务器端标签
user=mysql                  # 用户
basedir=/app/database/mysql # 软件目录
datadir=/data/3306          # 数据目录
server_id=6                 # 节点ID,一般主从时有用
port=3306                   # 监听的端口
socket=/tmp/mysql.sock      # sock 文件,本地客户端使用该文件可以链接
[mysql]                     # 客户端标签
socket=/tmp/mysql.sock      # 使用该文件链接数据库
EOF
  • Prepare the startup script

cd /app/database/mysql/support-files
cp mysql.server /etc/init.d/mysqld
  • service start

service mysqld start
  • systemd management

chkconfig --add mysqld
systemctl start mysqld

Log in to the database

  • Use the following command to log in to the database

mysql

MySQL series-install MySQL

Guess you like

Origin blog.51cto.com/15082392/2656446