准备环境
(1) 先查询是否有安装mariadb,如果有,先执行以下命令卸载mariadb
sudo apt-get remove --purge mariadb-server mariadb-client
(2) 安装libncurses.so.5和libtinfo.so.5库文件
在数据库登录时会用到,执行以下命令查询
find / -type f -name "libncurses.so.*"
find / -type f -name "libtinfo.so.*"
find / -type f -name "libnuma.so.*"
然后查询到的文件有可能不是libncurses.so.5和libtinfo.so.5,大概率文件可以在/usr/lib/找到,例如像下面这样,最后需要根据现有文件libncurses.so.*和libtinfo.so.*生成链接文件
ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6.5 /usr/lib64/libncurses.so.5
ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.5 /usr/lib64/libtinfo.so.5
ln -s /usr/lib/x86_64-linux-gnu/libnuma.so.1.0.0 /usr/lib64/libnuma.so.1
(3)编辑环境变量
vim /etc/profile
追加内容:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:/usr/lib32
source /etc/profile
2 下载mysql二进制安装包
例如:
mysql-9.0.1-linux-glibc2.17-x86_64.tar.xz
3、安装脚本
点击进入下面脚本页面
脚本内容如下:
#!/bin/bash#先查询是否有启动的mysql服务
mysql_process=`ps -aux |grep '[m]ysqld'`
if [ ! -z "$mysql_process" ];thenecho "mysqld服务已启动,请退出后再执行mysql安装!"exit 1;
fi#如果是手动上传mysql安装包,把它和此安装脚本放在同一目录下即可!
read -p "请输入需要安装的mysql的版本号,例如8.0.35:" versionif [ -z "${version}" ]then echo "输入安装的mysql的版本号为空!!!"exit 1
fi#apt install -y wget
#wget https://cdn.mysql.com/archives/mysql-8.0/mysql-${version}-linux-glibc2.17-x86_64.tar.xzis_exist=`ls ./ | grep mysql-${version}-linux-glibc2.17-x86_64.tar.xz`if [ -z "${is_exist}" ]then echo "mysql安装包不存在!!!现在开始下载中..."wget https://cdn.mysql.com/archives/mysql-8.0/mysql-${version}-linux-glibc2.17-x86_64.tar.xzis_exist=`ls ./ | grep mysql-${version}-linux-glibc2.17-x86_64.tar.xz`if [ -z "${is_exist}" ]then echo "mysql安装包不存在!!!请检查!!!"exit 1elseecho "${is_exist}存在,可以继续安装!"fi
elseecho "${is_exist}存在,可以继续安装!"
fiapt install -y libaio1if [ ! -e "/usr/lib64/libncurses.so.5" ]thenecho "/usr/lib64/libncurses.so.5不存在!"echo "请使用find / -type f -name 'libncurses.so.*'命令查询"exit 1
fiif [ ! -e "/usr/lib64/libtinfo.so.5" ]thenecho "/usr/lib64/libtinfo.so.5不存在!"echo "请使用find / -type f -name 'libtinfo.so.*'命令查询"exit 1
fiif [ ! -e "/usr/lib64/libnuma.so.1" ];thenecho "/usr/lib64/libnuma.so.1 不存在!"echo "请使用find / -type f -name ''命令查询"exit 1
ficheck_env(){id mysqlif [ 0 -eq "$?" ]then echo "mysql用户已经存在,无需创建"elseuseradd mysqlif [ 0 -eq "$?" ]then echo "mysql用户创建成功!"elseecho "mysql用户创建失败!!!"exit 1fifiif [ -d "/usr/local/mysql" ]thencd /usr/local && rm -rf mysql && cd -fi
}check_env && tar -xvf mysql-${version}-linux-glibc2.17-x86_64.tar.xz -C /usr/local && cd /usr/local && mv mysql-${version}-linux-glibc2.17-x86_64 mysql && cd mysql && mkdir data && chown -R mysql:mysql dataif [ $? -eq 0 ]thenecho "mysql安装环境准备成功!继续下一步"
elseecho "mysql安装环境准备失败!!!请检查"exit 1
ficat>/usr/local/mysql/my.cnf<<EOF
[mysql]
default-character-set=utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
#symbolic-links=0
#explicit_defaults_for_timestamp=true
lower_case_table_names=1
EOFif [ $? -eq 0 ]then echo "初始化mysql配置文件my.cnf成功!继续下一步"
elseecho "初始化mysql配置文件my.cnf失败!!!请检查"exit 1
fibin/mysqld --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --initializeif [ $? -eq 0 ]thenecho "初始化mysql实例成功!继续下一步"
elseecho "初始化mysql实例失败!!!请检查"exit 1
fiif [ -e /etc/my.cnf ] then rm -f /etc/my.cnf
fisupport-files/mysql.server startif [ $? -eq 0 ]thenecho "启动mysql实例成功!继续下一步"
elseecho "启动mysql实例失败!!!请检查"exit 1
fitemp_password=$(grep 'temporary password' /usr/local/mysql/data/mysql.err | awk '{print $NF}')echo "临时密码:${temp_password}"bin/mysql --connect-expired-password -uroot -p"${temp_password}" -e"alter user root@'localhost' identified by '123456';create user root@'%' identified by '123456';grant all privileges on *.* to root@'%';flush privileges;"
if [ $? -eq 0 ]thenecho "mysql用户密码设置成功!继续下一步"
elseecho "mysql用户密码设置失败!!!请检查"exit 1
fi#firewall-cmd --permanent --zone=public --add-port=3306/tcp
#firewall-cmd --reload
if [ $? -eq 0 ]thenecho "mysql端口放行成功!到此安装完成!开始使用MySQL吧!"
elseecho "mysql端口放行失败!!!请检查"
fi
echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/support-files' >> /etc/profile
echo "mysql执行路径已经添加到PATH环境变量中,生效请执行source /etc/profile 或是重启系统!"