centos 6.10 安装mysql 5.7.27

时间:2021-03-14 16:47:33
  • 操作系统Centos 6.10 64位
  • Mysql 版本 5.7.27 , 从官网下载
  • 该教程是Mysql shell安装脚本,脚本运行结束后需要重置密码,以及必要的授权操作等
  • 该教程对外端口设置为50000
  • 该教程Mysql 的BASE 路径是 /usr/local/mysql/app/mysql
  • 该教程Mysql 的 DATA 路径是 /usr/local/mysql/data/
#!/bin/bash
yum install wget numactl libaio-devel -y
rpm -qa |grep mysql mkdir /usr/local/mysql
mkdir -p /usr/local/mysql/app
mkdir -p /usr/local/mysql/data/
mkdir -p /usr/local/mysql/log/ cd /usr/local/src/
#wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
wget -O mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz http://download.zhufunin.com/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
tar zxf mysql-5.7.-linux-glibc2.-x86_64.tar.gz
mv /usr/local/src/mysql-5.7.-linux-glibc2.-x86_64 /usr/local/mysql/app/mysql groupadd mysql
useradd -r -g mysql -s /bin/false mysql cat > /etc/my.cnf <<EOF [client]
default-character-set=utf8
socket=/tmp/mysql.sock
[mysqld]
#skip-name-resolve
port =
socket = /tmp/mysql.sock
basedir = /usr/local/mysql/app/mysql
datadir= /usr/local/mysql/data/
character-set-server=utf8
skip-character-set-client-handshake=
default-storage-engine=INNODB
max_allowed_packet = 500M
explicit_defaults_for_timestamp=
log-output=FILE
general_log=
general_log_file=/usr/local/mysql/log/general.log
slow_query_log = ON
slow_query_log_file = /usr/local/mysql/log/slow-query.log
long_query_time =
log-error = /usr/local/mysql/log/error.log
EOF chown -R mysql:mysql /usr/local/mysql/ /usr/local/mysql/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql/app/mysql/ --datadir=/usr/local/mysql/data/ cp /usr/local/mysql/app/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld chkconfig --add mysqld
service mysqld start ln -s /usr/local/mysql/app/mysql/bin/mysql /usr/local/bin/
echo "export PATH=$PATH:/usr/local/mysql/app/mysql/bin/" >> /etc/profile
source /etc/profile echo "***************************"
echo "***************************"
echo "Please read below carefully"
echo "***************************"
echo "***************************"
echo "You must change your root password before you do anythings"
echo "Below is your password"
echo "###########################"
tail - /usr/local/mysql/log/error.log|grep 'temporary password'|awk -F ':' '{print $4}'|awk '{print $1}'|tail -
echo "###########################"
echo "mysql -hlocalhost -uroot -p"
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword';"
echo "***************************"
echo "After you changed your passowrd, you can change root access right by follow commands"
echo "***************************"
echo "use mysql;"
echo "select host,user from user where user='root';"
echo "create USER 'root'@'%' IDENTIFIED BY 'YourPassword';"
echo "grant all privileges on *.* to 'root'@'%' with grant option;"