MYSQL的安装

【MYSQL的安装】亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述MYSQL的安装相关的知识,希望能为你提供帮助。
1、在阿里云服务器搭建...略
2、通过编译、二进制安装mysql5.7

  • 编译安装
    [root@centos7 ~]# tar xvf mysql-5.6.51.tar.gz -C /usr/local/src**下载并解压缩源码包**

源码编译安装 MySQL
[root@centos7 ~]# cd /usr/local/src/mysql-5.6.51
[root@centos7 mysql-5.6.51]# cmake .\\
准备环境变量
[root@centos7 ~]# echo \'PATH=/apps/mysql/bin:$PATH\' > /etc/profile.d/mysql.sh
[root@centos7 ~]# ./etc/profile.d/mysql.sh
生成数据库文件
[root@centos7 ~]# cd/apps/mysql
[root@centos7 mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
准备配置文件
[root@centos7 ~]# cp -b /apps/mysql/support-files/my-default.cnf /etc/my.cnf
#针对旧版本或mariadb-10.2.18.tar.gz
cp /apps/mysql/support-files/my-huge.cnf/etc/my.cnf
准备启动脚本,并启动服务
[root@centos7 ~]# cp /apps/mysql/support-files/mysql.server/etc/init.d/mysqld
[root@centos7 ~]# chkconfig --add mysqld
[root@centos7 ~]# service mysqld start
安全初始化
[root@centos7 ~]# mysql_secure_installation
- ### 二进制安装 ```bash #!bin/bash/ . /etc/init.d/functions RC_DIR=`pwd` MYSQL=\'mariadb-10.4.21-linux-glibc_214-x86_64.tar.gz\' #URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.4.21/bintar-linux-glibc_214-x86_64/ COLOR=\'echo -e \\E[01; 31m\' END=\'\\E[0m\' MYSQL_ROOT_PASSWORD=xiaozzcheck (){ if [ $UID -ne 0 ]; then action "当前用户不是root,安装失败" false exit 1 ficd $SRC_DIR #rpm -q wget || yum -y -q install wget #wget $URL/$MYSQL if [ !-e $MYSQL ]; then $COLOR"缺少${MYSQL}文件"$END $COLOR"请将相关软件放在${SRC_DIR}目录下"$END exit elif [ -e /usr/local/mysql ]; then action "数据库已存在,安装失败" false exit else return fi }install_mysql(){ $COLOR"开始安装Maridb数据库..."$END yum -y -q install libaio numactl-libs cd $SRC_DIR tar xf $MYSQL -C /usr/local/ MYSQL_DIR=`echo $MYSQL| sed -nr \'s/^(.*[0-9]).*/\\1/p\'` ln -s /usr/local/$MYSQL_DIR /usr/local/mysql chown -R root.root /usr/local/mysql/ id mysql & > /dev/null || { useradd -s /sbin/nologin -r mysql ; action "创建mysql用户"; } echo \'PATH=/usr/local/mysql/bin/:$PATH\' > /etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh ln -s /usr/local/mysql/bin/* /usr/bin/ cat > /etc/my.cnf < < -EOF [mysqld] server-id=1 log-bin datadir=/data/mysql socket=/data/mysql/mysql.socklog-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock EOF[ -d /data ] || mkdir /data mysqld --initialize --user=mysql --datadir=/data/mysql cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start [ $? -ne 0 ] & & { $COLOR"数据库启动失败,退出!"$END; exit; } sleep 3 MYSQL_OLDPASSWORD=`awk \'/A temporary password/{print $NF}\' /data/mysql/mysql.log` mysqladmin -uroot -p$MYSQL_OLDPASSWORD password $MYSQL_ROOT_PASSWORD & > /dev/null action "数据库安装完成" }check install_mysql

3、二进制安装mariadb10.4
[root@centos8 data]# tar vxf mariadb-10.4.21-linux-glibc_214-x86_64.tar.gz -C /usr/local/ [root@centos8 local]# ln -s mariadb-10.4.21-linux-glibc_214-x86_64 mysql [root@centos8 local]# chown -R root.root mysql/ [root@centos8 local]# echo \'PATH=/usr/local/mysql/bin:$PATH\' > /etc/profile.d/mysql.sh [root@centos8 local]# source /etc/profile.d/mysql.sh [root@centos8 local]# echo $PATH /usr/local/mysql/bin:/apps/httpd/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@centos8 local]# useradd -r -s /sbin/nologin mysql [root@centos8 local]# mkdir -pv /data/sqldb/3306/{log,data,pid,socket,tmp} mkdir: created directory \'/data/sqldb\' mkdir: created directory \'/data/sqldb/3306\' mkdir: created directory \'/data/sqldb/3306/log\' mkdir: created directory \'/data/sqldb/3306/data\' mkdir: created directory \'/data/sqldb/3306/pid\' mkdir: created directory \'/data/sqldb/3306/socket\' mkdir: created directory \'/data/sqldb/3306/tmp\' [root@centos8 local]# chown -R mysql.mysql /data/sqldb/ [root@centos8 local]# chmod -R 770 /data/sqldb/ [root@centos8 ~]# #\\cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf [root@centos8 ~]# cat /etc/my.cnf [mysqld] port=3306 socket=/tmp/sqldb/3306/pid/mysql.pid datadir =/data/sqldb/3306/data tmpdir=/data/sqldb/3306/tmp innodb_file_per_table=1 skip_name_resolve=1 log-error=/data/sqldb/3306/log/error.log [root@centos8 ~]# cd /usr/local/mysql/ [root@centos8 mysql]# ls binCREDITSincludelibmysql-testREADME-wsrepsharesupport-files COPYINGdocsINSTALL-BINARYmanREADME.mdscriptssql-benchTHIRDPARTY [root@centos8 mysql]# scripts/mysql_install_db --dtatadir=/data/sqldb/3306/ --user=mysql [root@centos8 mysql]# cd /data/sqldb/3306/data [root@centos8 data]# ls aria_log.00000001aria_log_controlib_buffer_poolibdata1ib_logfile0ib_logfile1 [root@centos8 data]# cd /usr/local/mysql/ [root@centos8 mysql]# ls binCREDITSincludelibmysql-testREADME-wsrepsharesupport-files COPYINGdocsINSTALL-BINARYmanREADME.mdscriptssql-benchTHIRDPARTY [root@centos8 mysql]# cd support-files [root@centos8 support-files]# cp mysql.server /etc/init.d/mysqld [root@centos8 ~]# chkconfig --add mysqld [root@centos8 ~]# chkconfig mysqld on [root@centos8 ~]# systemctl start mysqld


    推荐阅读