学以致用二十七-----Centos7.5二进制安装mysql5.7.23
首先去官网查看mysql版本。才一个礼拜不到,我之前下载的是mysql5.7.23,现在在官网页面已然找不到了,只有5.7.24版本,不得不说更新真快。不过我下载的是mysql5.7.23,所以还是安装的是5.7.23
下载地址:https://www.mysql.com/downloads/
下载页面
----------------------->
下载下来后,比较坑的是。竟然没有源码编译安装的版本了,只有二进制版本。好吧,安装确实也比编译安装快了。。。。。
也是写了脚本来安装,自从shell脚本入门后,就要多尝试写脚本,加深印象。虽写的很low,希望之后装mysql8.0能复用
1 #!/usr/bin/bash 2 #lion 3 #2018-10-20 4 #install mysql 5 6 . common/color.sh 7 . common/download.conf 8 9 files_prefix=('mysql' 'python' 'vim') 10 soft_path=/soft 11 mysql_install_path=/usr/local/mysql 12 mysql_lib_path=/var/lib/mysql 13 cmake_package='cmake-3.12.3.tar.gz' 14 cmake_ver='cmake-3.12.3' 15 mysql_ver='mysql-5.7.23-linux-glibc2.12-x86_64' 16 mysql_file=$(ls | grep -i ${files_prefix[0]}) 17 yum_list='sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git lsof ncurses-devel perl-Module-Build.noarc libaio' 18 yum_install() 19 { 20 for i in ${yum_list};do 21 yum -y install ${i} 22 done 23 } 24 check_package() 25 { 26 my=$(ls | grep -i ${files_prefix[0]}) 27 py=$(ls | grep -i ${files_prefix[1]}) 28 vm=$(ls | grep -i ${files_prefix[2]}) 29} 30 Download_files() 31 { 32 Echo_blue "[+]Begin download install Package...." 33 [ ! -d "${soft_path}" ] && mkdir ${soft_path} 34 cd ${soft_path} 35 sleep 2 36 check_package 37 if [ -z ${my} ];then 38 wget -c ${Mysql_download} 39 if [ $? -eq 0 ] ;then 40 Echo_green "Mysql Package download sucessful!" 41 else 42 Echo_red "Download failure.Try it again" 43 exit 1 44 fi 45 else 46 Echo_red "The Package is existed" 47 fi 48 #[ ! -f ${cmake_package} ] && wget -c ${cmake_download} 49 } 50 Check_db() 51 { 52 Echo_yellow "[+]Check db is or not installed....." 53 sleep 1 54 if [ -z $(rpm -qa | grep mariadb) ]; then 55 Echo_white "No db is installed.Will install New DB" 56 else 57 Echo_gray "[+]Rmoving old db......." 58 sleep 1 59 rpm -e --nodeps $(rpm -qa | grep mariadb) 60 fi 61 } 62 add_user() 63 { 64 cat /etc/passwd | grep mysql &> /dev/null 65 [ $? -ne 0 ] && useradd mysql 66 } 67 add_path() 68 { 69 [ ! -d ${mysql_install_path} ] && mkdir ${mysql_install_path} 70 [ ! -d ${mysql_lib_path} ] && mkdir ${mysql_lib_path} 71 chown -R mysql:mysql ${mysql_lib_path} 72 } 73 74 tar_gz() 75 { 76 local FileName=$1 77 local DirName=$2 78 cd ${soft_path} 79 if [ ! -f ${FileName} ];then 80 Echo_red "The ${FileName} does not exist" 81 else 82 Echo_blue '[+]Begin uncompress files...' 83 tar zxvf ${FileName} 84 cd ${DirName} 85 fi 86 } 87 cmake_install() 88 { 89 tar_gz ${cmake_package} ${cmake_ver} 90 ./bootstrap 91 gmake -j `grep 'processor' /proc/cpuinfo | wc -l ` 92 make install 93 } 94 95 tar_mysql() 96 { 97 tar_gz ${my} ${mysql_ver} 98 # cmake -DCMAKE_INSTALL_PREFIX=${mysql_install_path} -DMYSQL_DATADIR=${mysql_lib_path} -DSYSCONFDIR=/etc 99 # make;make install 100 mv * ${mysql_install_path} 101 cd ${soft_path} && rm -rf ${mysql_ver} 102 } 103 104 init_mysql() 105 { 106 Echo_blue 'mysql initialize' 107 [ -d ${mysql_lib_path} ] && cd ${mysql_lib_path} && rm -rf * 108 cd ${mysql_install_path} 109 ./bin/mysqld --initialize --user=mysql --datadir=${mysql_lib_path} 110 ./bin/mysql_ssl_rsa_setup --datadir=${mysql_lib_path} 111 } 112 set_start() 113 { 114 cd ${mysql_install_path} 115 cp support-files/mysql.server /etc/init.d/mysql 116 ln /usr/local/mysql/bin/mysql /usr/bin/mysql 117 } 118 db_install() 119 { 120 #yum_install 121 Download_files 122 Check_db 123 Echo_aqua "Begin install Mysql 5.7.23" 124 sleep 1 125 add_user 126 add_path 127 # cmake_install 128 tar_mysql 129 init_mysql 130 set_start 131 [ $? -eq 0 ] && Echo_green 'Mysql 5.7.23 initialize successful' 132 } 133 db_install 2>&1 | tee /root/mysql_install.log
Mysql_download='https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz' Python_download='https://www.python.org/ftp/python/3.7.2/Python-3.7.1.tar.xz' cmake_download='https://cmake.org/files/v3.12/cmake-3.12.3.tar.gz'
脚本运行效果
说明:mysql初始化后,会提供一个临时密码。需要记录下来
mysql 启动成功,但是进mysql的时候,报错
原因是my.cnf里[mysql] 和[client] 没有指定socket路径。很坑爹的是,我安装的这版连my.cnf也没有了。还是到网上下的模板
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /usr/local/mysql datadir = /var/lib/mysql port = 3306 # server_id = ..... socket = /tmp/mysqld.sock # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER explicit_defaults_for_timestamp=true [client] default-character-set = utf8 socket = /tmp/mysqld.sock [mysql] default-character-set = utf8 socket = /tmp/mysqld.sock
sql_mode没有指定的话,初始化的时候会有警告
开启查询缓存
explicit_defaults_for_timestamp=true
第一次进mysql,用临时密码进去后,会提示更改密码
mysql> SET PASSWORD = PASSWORD('123456') ;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
好像在8.0版本重设密码是,以后要实践一下
mysql> SET PASSWORD = '123456';
Query OK, 0 rows affected (0.01 sec)
至此简单的mysql就安装完毕。当然还有很多配置,需要在my.cnf中去配置。