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] port = $1 socket = ${data_dir}/mysqld.sock default-character-set=utf8 [mysqld] port = $1 socket = ${data_dir}/mysqld.sock basedir =${base_dir} datadir = ${data_dir} back_log = 500 skip-name-resolve skip-external-locking concurrent_insert = 2 delay-key-write = ALL key_buffer_size = 256M max_allowed_packet = 128M table_open_cache = 512 sort_buffer_size = 2M net_buffer_length = 8K read_buffer_size = 2M read_rnd_buffer_size = 512K myisam_sort_buffer_size = 64M thread_stack = 512K log-bin = mysql-bin binlog_format = mixed relay_log = relay-bin server-id = $1 binlog_cache_size = 8M max_binlog_size = 1024M max_relay_log_size = 1024M expire_logs_days = 3 thread_cache_size = 8 query_cache_size = 32M max_connections = 32000 max_user_connections=5000 tmp_table_size = 256M long_query_time = 1 slow_query_log innodb_file_per_table innodb_buffer_pool_size = 1G innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT innodb_file_format = barracuda innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_fast_shutdown = 1 explicit_defaults_for_timestamp=off max_user_connections=500 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES innodb_io_capacity = 2000 innodb_io_capacity_max = 10000 innodb_open_files = 1000 federated event_scheduler=1 default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-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安装完成