install_mysql-8.0.sh

install_mysql-8.0.sh

@H_502_2@#!/bin/env bash # ================================================= # Author: renwole.com # # See: https://renwole.com/archives/2215 # # Description: MysqL automatic installation tool # # ================================================= export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin Install_MysqL() { # CentOS 8 MysqL: error while loading shared libraries: libncurses.so.5 yum install ncurses ncurses-compat-libs -y # Install dependencies setenforce 0 yum -y install epel-release yum -y install wget tar jemalloc jemalloc-devel gcc gcc-c++ # MysqL configuration MysqL_version="8.0.27" MysqL_password="nd.mm#2021" mkdir -p /apps/server/MysqL/data MysqL_install_dir="/apps/server/MysqL" MysqL_data_dir="/apps/server/MysqL/data" download_MysqL="https://mirrors.tuna.tsinghua.edu.cn/MysqL/downloads" # Download MysqL cd /mnt useradd -M -s /sbin/nologin MysqL >/dev/null 2>&1 wget -c ${download_MysqL}/mysql-8.0/MysqL-${MysqL_version}-linux-glibc2.12-x86_64.tar.xz echo "========== Start installing MysqL ============" tar xJf MysqL-${MysqL_version}-linux-glibc2.12-x86_64.tar.xz \mv MysqL-${MysqL_version}-linux-glibc2.12-x86_64/* ${MysqL_install_dir} if [[ -d "${MysqL_install_dir}/support-files" ]]; then rm -rf MysqL-${MysqL_version}-linux-glibc2.12-x86_64 else rm -rf ${MysqL_install_dir} echo "Error: MysqL install Failed, Please contact the author" kill -9 $$ fi # Initialize the database ${MysqL_install_dir}/bin/MysqLd --initialize-insecure --user=MysqL --lower-case-table-names=1 --basedir=${MysqL_install_dir} --datadir=${MysqL_data_dir} chown -R root . ${MysqL_install_dir} chown -R MysqL.MysqL ${MysqL_data_dir} \cp -f ${MysqL_install_dir}/support-files/MysqL.server /etc/init.d/MysqLd sed -i "s@^basedir=.*@basedir=${MysqL_install_dir}@" /etc/init.d/MysqLd sed -i "s@^datadir=.*@datadir=${MysqL_data_dir}@" /etc/init.d/MysqLd sed -i "s@/usr/local/MysqL@${MysqL_install_dir}@g" ${MysqL_install_dir}/bin/MysqLd_safe sed -i 's@executing MysqLd_safe@executing MysqLd_safe\nexport LD_PRELOAD=/usr/lib64/libjemalloc.so@' ${MysqL_install_dir}/bin/MysqLd_safe echo 'PATH=$PATH:'${MysqL_install_dir}'/bin' >/etc/profile.d/mariadb_renwole.com.sh # my.conf configuration cat > /etc/my.cnf << EOF [client] port = 3306 socket = /tmp/MysqL.sock default-character-set = utf8mb4 [MysqL] prompt="MysqL [\\d]> " no-auto-rehash [MysqLd] port = 3306 socket = /tmp/MysqL.sock default_authentication_plugin = MysqL_native_password basedir = ${MysqL_install_dir} datadir = ${MysqL_data_dir} pid-file = ${MysqL_data_dir}/MysqL.pid user = MysqL bind-address = 0.0.0.0 server-id = 1 init-connect = 'SET NAMES utf8mb4' character-set-server = utf8mb4 collation-server = utf8mb4_0900_ai_ci lower-case-table-names = 1 skip-name-resolve #skip-networking back_log = 300 max_connections = 1000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 128 max_allowed_packet = 500M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 4M thread_cache_size = 8 ft_min_word_len = 4 log_bin = MysqL-bin binlog_format = mixed binlog_expire_logs_seconds = 604800 log_error = ${MysqL_data_dir}/MysqL-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = ${MysqL_data_dir}/MysqL-slow.log performance_schema = 0 explicit_defaults_for_timestamp lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [MysqLdump] quick max_allowed_packet = 500M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M EOF # Set up MysqL chmod 600 /etc/my.cnf chmod +x /etc/init.d/MysqLd systemctl enable MysqLd systemctl start MysqLd ${MysqL_install_dir}/bin/MysqL -uroot -hlocalhost -e "create user root@'127.0.0.1' identified by \"${MysqL_password}\";" ${MysqL_install_dir}/bin/MysqL -uroot -hlocalhost -e "grant all privileges on *.* to root@'127.0.0.1' with grant option;" ${MysqL_install_dir}/bin/MysqL -uroot -hlocalhost -e "grant all privileges on *.* to root@'localhost' with grant option;" ${MysqL_install_dir}/bin/MysqL -uroot -hlocalhost -e "alter user root@'localhost' identified by \"${MysqL_password}\";" ${MysqL_install_dir}/bin/MysqL -uroot -p${MysqL_password} -e "reset master;" rm -rf /etc/ld.so.conf.d/{MysqL,mariadb,percona,alisql}*.conf echo "${MysqL_install_dir}/lib" > /etc/ld.so.conf.d/MysqL_renwole.com.conf ldconfig echo "========== MysqL installing Successfully =====" echo echo "==============================================" echo " Thank you for using Renwole.com script" echo "==============================================" echo "MysqL:" echo "account: root" echo "password: ${MysqL_password}" echo "database: ${MysqL_data_dir}" echo "==============================================" } Install_MysqL source /etc/profile

相关文章

mac 使用 tcpdump 抓包指定端口
自动将windows本地公钥写入linux服务器的bat
mac查看占用端口的进程
循环读取 txt 文件中的链接并下载
从 ttc 中提取 ttf 文件: ttc2ttf.pe
mac osx python 安装 mysqlclient