安装Mysql-5.7.13脚本

时间:2022-09-23 21:05:12

安装Mysql-5.7.13,此脚本最后会查找到临时密码,后面登进数据库中更改密码

[root@ZHONG-LONG javascripts]# vim 08-mysql.sh 
#!/bin/bash
##############Mysql-5.7.13安装
mkdir -p /data/local
cd /usr/src/project
tar zxvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz -C /data/local/
cd /data/local/
ln -s mysql-5.7.13-linux-glibc2.5-x86_64 mysql
mv /etc/my.cnf /etc/my.cnf.bak
cat >> /etc/my.cnf << 'EOF'
[client]
port=3306
socket=/data/local/mysql/mysql.sock

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

skip-external-locking
skip-name-resolve

user=mysql
bind-address=0.0.0.0
port=3306
basedir=/data/local/mysql
datadir=/data/local/mysql/data
tmpdir=/data/local/mysql/temp
# server_id = .....
socket=/data/local/mysql/mysql.sock
log-error=/data/local/mysql/logs/mysql_error.log
pid-file=/data/local/mysql/mysql.pid
open_files_limit=10240
back_log=600
max_connections=500
max_connect_errors=6000
wait_timeout=605800
#open_tables=600
#table_cache = 650
#opened_tables = 630

max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=300
query_cache_type=1
query_cache_size=256M
query_cache_limit=2M
query_cache_min_res_unit=16k

tmp_table_size=256M
max_heap_table_size=256M

key_buffer_size=256M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M

lower_case_table_names=1

default-storage-engine=INNODB

innodb_buffer_pool_size=2G
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_flush_method=O_DIRECT
#####################
#thread_concurrency=32
long_query_time=1
slow-query-log=on
slow-query-log-file=/data/local/mysql/logs/mysql-slow.log
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqldump]
quick
max_allowed_packet=32M

[mysqld_safe]
log-error=/data/local/mysql/logs/mysqld.log
pid-file=/data/local/mysql/mysqld.pid

default-time_zone = '+8:00'
log_timestamps = SYSTEM
EOF
mkdir /data/local/mysql/{logs,temp,data}
groupadd mysql
useradd mysql -g mysql
yum install -y libaio
chown -R mysql.mysql /data/local/mysql-5.7.13-linux-glibc2.5-x86_64
chown -R mysql.mysql /data/local/mysql
/data/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/local/mysql/ --datadir=/data/local/mysql/data
echo "export PATH=/data/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
/data/local/mysql/bin/mysql_ssl_rsa_setup
/data/local/mysql/support-files/mysql.server start
cp /data/local/mysql/support-files/mysql.server /etc/init.d/
grep "password" /data/local/mysql/logs/mysql_error.log

根据最后查找到的临时密码登进数据库中更改

[root@ZHONG-LONG ~]# mysql -uroot -p

mysql> set password=password('密码');        --------需要更改的root密码

mysql> flush privileges;

mysql> exit

至此使用mysql-5.7.13的二进制版本安装完毕。