linux下安装mysql

mysql安装

1、mysql下载路径

https://pan.baidu.com/s/1MPuTenlhsX-bJrEsPD-wSw

mysql安装脚本

mysql_install-5.7.20.sh

#!/bin/bash

if [ $# -ne 1 ]
then
        echo "Usage: $0 port "
    exit 1
fi

( lsof -i:$1 &>/dev/null || which mysql$1 &>/dev/null ) && ( echo "error: the port $1 has been used" ; exit 11 )
test $? -eq 11 && exit 1

############################

base_dir=/usr/local/mysql$1
data_dir=/mysql/mysql$1
mysql_file='mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz'

echo "install ing ........"


############################

useradd mysql 2>/dev/null
mkdir ${data_dir} -p  2>/dev/null
chown mysql:mysql ${base_dir} ${data_dir} -R

############################

#download mysql install package and install it
test -f $mysql_file || (echo "download mysql software package error!" ;exit 1)
test $? -eq 1 && exit 1

echo "install mysql ......"

tar -zxvf $mysql_file -C /usr/local
cd /usr/local && mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql$1

cd ${base_dir}
ln -s ${base_dir}/support-files/mysql.server /etc/init.d/mysql$1

echo 'export PATH=/usr/local/mysql3306/bin:$PATH' >> /etc/profile
source /etc/profile

chown mysql:mysql ${base_dir} ${data_dir} -R

printf "[client]\nport = $1\nsocket = ${data_dir}/mysqld.sock\ndefault-character-set=utf8\n\n[mysqld]\nport = $1\nsocket = ${data_dir}/mysqld.sock\nbasedir =${base_dir} \ndatadir = ${data_dir}\nback_log = 500\nskip-name-resolve\nskip-external-locking\nconcurrent_insert = 2\ndelay-key-write = ALL\nkey_buffer_size = 256M\nmax_allowed_packet = 128M\ntable_open_cache = 512\nsort_buffer_size = 2M\nnet_buffer_length = 8K\nread_buffer_size = 2M\nread_rnd_buffer_size = 512K\nmyisam_sort_buffer_size = 64M\nthread_stack = 512K\nlog-bin = mysql-bin\nbinlog_format = mixed\nrelay_log = relay-bin\nserver-id = $1\nbinlog_cache_size = 8M\nmax_binlog_size = 1024M\nmax_relay_log_size = 1024M\nexpire_logs_days = 3\nthread_cache_size = 8\nquery_cache_size = 32M\nmax_connections = 32000\nmax_user_connections=5000\ntmp_table_size = 256M\nlong_query_time = 1\nslow_query_log\ninnodb_file_per_table\ninnodb_buffer_pool_size = 1G\ninnodb_flush_log_at_trx_commit = 2\ninnodb_flush_method = O_DIRECT\ninnodb_file_format = barracuda\ninnodb_log_file_size = 256M\ninnodb_log_files_in_group = 3\ninnodb_fast_shutdown = 1\nexplicit_defaults_for_timestamp=off\nmax_user_connections=500\nsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES\nsql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES\ninnodb_io_capacity = 2000\ninnodb_io_capacity_max = 10000\ninnodb_open_files = 1000\nfederated\nevent_scheduler=1\ndefault-storage-engine=INNODB\ncharacter-set-server=utf8\ncollation-server=utf8_general_ci\n\n[mysqldump]\nquick\nmax_allowed_packet = 16M\n\n[mysql]\nno-auto-rehash\n\n[myisamchk]\nkey_buffer_size = 20M\nsort_buffer_size = 20M\nread_buffer = 2M\nwrite_buffer = 2M\n\n[mysqlhotcopy]\ninteractive-timeout" > /etc/my.cnf


#./scripts/mysql_install_db --defaults-file=${base_dir}/etc/my.cnf --basedir=${base_dir} --datadir=${data_dir} || exit 1
${base_dir}/bin/mysqld --initialize --user=mysql --basedir=${base_dir} --datadir=${data_dir} || exit 1


chown mysql:mysql ${base_dir} ${data_dir} -R
/etc/init.d/mysql$1 start && echo "mysql has been install successfully!"


############################
############################
chkconfig --add mysql$1
chkconfig  mysql$1 on

 

2、执行 sh mysql_install-5.7.13.sh ${MYSQL_PORT_NO} 脚本

sh mysql_install-5.7.13.sh 3306

 

 Mysql安装时,会打印出root账户的临时密码,记下临时密码

3、登录mysql并修改临时密码,并给root用户在其他机器可以登录的权限,在安装完成后再取消该权限。命令如下:

mysql -uroot -p 

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
use mysql
update user set Host = "%" where User = "root";

 

至此mysql安装完成

 

posted on 2018-06-29 15:01  海之浪子  阅读(124)  评论(0编辑  收藏  举报

导航