MYSQL的安装

Posted 小卓卓的世界

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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=xiaozz

check (){
if [ $UID -ne 0 ]; then
  action "当前用户不是root,安装失败" false
  exit 1
fi

cd $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.sock

log-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
bin      CREDITS  include         lib  mysql-test  README-wsrep  share      support-files
COPYING  docs     INSTALL-BINARY  man  README.md   scripts       sql-bench  THIRDPARTY
[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.00000001  aria_log_control  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
[root@centos8 data]# cd /usr/local/mysql/
[root@centos8 mysql]# ls
bin      CREDITS  include         lib  mysql-test  README-wsrep  share      support-files
COPYING  docs     INSTALL-BINARY  man  README.md   scripts       sql-bench  THIRDPARTY
[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

以上是关于MYSQL的安装的主要内容,如果未能解决你的问题,请参考以下文章

从mysql的片段中加载ListView

连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途

使用 json rereiver php mysql 在片段中填充列表视图

PHP代码-psysh调试代码片段工具

关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段