debian10编译安装mysql
卸载mariadb
root@192:/mysql# rpm -qa | grep mariadb
root@192:/mysql#
创建mysql用户 创建mysql目录
useradd -r mysql -M -s /bin/nologin
-M 不创建用户的家目录
mkdir -p /usr/local/{data,mysql,log}
root@192:/usr/local/mysql# mkdir -p /usr/local/mysql/data
root@192:/usr/local/mysql# mkdir -p /usr/share/man
从官网下载安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz
安装包位置
安装编译工具
因为我这是debian10操作系统,跟centos操作系统有点不一样,比较麻烦没办法直接安装这些依赖,
直接找包安装
https://www.debian.org/distrib/packages
俩种解决方法,第一种就是去搜索各种依赖的安装
第二种,就是去安装这些依赖的tar.gz
https://blog.csdn.net/weixin_45191791/article/details/110136458
aptitude -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf cmake #所需要的依赖
第一个依赖的问题
ncurses ncurses-devel 这个依赖
aptitude -y install libncurses5-dev
第二个依赖的问题
openssl-devel 这个依赖
aptitude -y install libssl-dev #先安装这个
aptitude -y install openssl #再安装这个
第三个安装包
gcc gcc-c++这个
aptitude install -y bison #直接安装就好
第四个安装包
aptitude -y install gcc-8
aptitude -y install g++-8
第五个安装包
aptitude -y install gcc automake autoconf libtool make
第六个安装包
aptitude -y install libc6-dev
第七个安装包
cmake
安装地址
https://cmake.org/files/v3.5/
我们选择下载直接可以使用的版本,右键保存链接地址,打开Linux系统(以Ubuntu为例)
下载安装
wget -c https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz
解压
tar -zxvf cmake-3.5.2-Linux-x86_64.tar.gz
mv cmake-3.5.2-Linux-x86_64 cmake
vim /etc/profile #添加环境变量
export CMAKE_HOME=/mysql/cmake/bin
export PATH=$CMAKE_HOME:$PATH
保存退出,刷新环境变量
source /etc/profile
检验是否安装成功
cmake -version
查看一下这些依赖有没有安装好
有了下面这些依赖,都可以压缩打包到其他服务器上面直接安装了
ls /var/cache/apt/archives/
解压安装包
tar -zxvf mysql-boost-5.7.27.tar.gz -C /usr/local/
mv mysql-5.7.27 mysql #移动改名称
cd /usr/local/mysql
编译,我这里报错了
cmake .
-DWITH_BOOST=boost/boost_1_59_0/
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DSYSCONFDIR=/etc
-DMYSQL_DATADIR=/usr/local/mysql/data
-DINSTALL_MANDIR=/usr/share/man
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DEXTRA_CHARSETS=all
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_EMBEDDED_SERVER=1
-DENABLED_LOCAL_INFILE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
遇到报错
尝试解决方法
aptitude -y install libgmp-dev
aptitude -y install flex
解决不了 #
尝试新的安装mysql
cd /etc/apt/
vim /etc/apt//sources.list #先备份
#Ctrl+Insert :wq
deb http://mirrors.163.com/debian/ buster main non-free contrib
deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ buster main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
apt update
aptitude install -y binutils build-essential cmake gawk bison flex texinfo automake autoconf libtool cvs libncurses5-dev libglib2.0-dev gettext intltool subversion
创建mysql目录
mkdir /ok
cd /ok
apt install -y openssl libssl-dev
useradd -s /sbin/nologin mysql
mkdir /server/
mkdir /server/mysql
mkdir /server/mysql/data
mkdir /server/mysql/etc
mkdir /server/mysql/tmp
下载mysql安装包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.35.tar.gz
tar -zxvf ./mysql-boost-5.7.35.tar.gz
cd ./mysql-boost-5.7.35
编译
cmake -DCMAKE_INSTALL_PREFIX=/server/mysql -DMYSQL_DATADIR=/server/mysql/data -DSYSCONFDIR=/server/mysql/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/server/mysql/tmp/mysql.sock -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost/boost_1_59_0/ -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
又出现新的报错
解决方法
aptitude -y install libhdf5-serial-dev hdf5-tools
卸载这个
aptitude remove -y gcc-8-base
从新安装
这俩个还是不一样,不是咱们想安装的卸载
aptitude -y remove libhdf5-dev
完美解决
aptitude -y install pkg-config
make
成功截图
make install
chown -R mysql:mysql /server/mysql
cd /server/mysql
#生成临时密码,要保存下来
bin/mysqld --initialize --user=mysql --basedir=/server/mysql/ --datadir=/server/mysql/data/
>K,>Nkdyv2p8 初始化密码
添加环境变量
vim /etc/profile 环境变量都在这个文件里面最后一行
PATH=/usr/local/mysql/bin:$PATH 最后一行
[root mysql]# source /etc/profile 重启一下 环境变量文件
[roott mysql]# echo $PATH 查看一下有没有加载上
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
7
我这里存放位置不一样
修改配置文件
root@192:/etc/mysql# cd /etc/mysql/
root@192:/etc/mysql# ls
conf.d mariadb.cnf mariadb.conf.d my.cnf my.cnf.fallback
root@192:/etc/mysql# cp my.cnf my.cnf_bak #优先备份一下
vim my.cnf
插入一下代码
[client]
port=3306
socket=/server/mysql/tmp/mysql.sock
default-character-set = utf8
[mysqld]
port=3306
bind-address=127.0.0.1
basedir=/server/mysql
datadir=/server/mysql/data
socket=/server/mysql/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# time zone
default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB
[mysqld_safe]
log-error=/server/mysql/data/i-qluq9hly.err #刚才保存的
pid-file=/server/mysql/data/i-qluq9hly.pid #刚才保存的
启动数据库
cd /server/mysql/
root@192:/server/mysql# ls
bin docs include LICENSE mysql-test README-test support-files
data etc lib man README share tmp
root@192:/server/mysql# ./bin/mysqld_safe --user=mysql &
[2] 11860
root@192:/server/mysql# Logging to '/server/mysql/data/i-qluq9hly.err'.
2022-05-25T05:58:06.598996Z mysqld_safe Starting mysqld daemon with databases from /server/mysql/data
2022-05-25T05:58:08.534790Z mysqld_safe mysqld from pid file /server/mysql/data/i-qluq9hly.pid ended
[2]+ 已完成 ./bin/mysqld_safe --user=mysql
设置MySQL 启动 重启加载服务
cp support-files/mysql.server /etc/init.d/mysql
cp bin/mysqld /etc/init.d/
chmod +x /etc/init.d/mysql
update-rc.d mysql defaults
service mysql start
cp bin/mysql /usr/bin/mysql
chmod +x /usr/bin/mysql
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'OkPlus123456' PASSWORD EXPIRE NEVER;
flush privileges;
service mysqld stop
修改密码
修改密码第一种方式
set password='BImuyu@11..'
第二种方式
mysqladmin -u root -p’旧密码’ password ‘新密码’
缓存mysql依赖
root@192:/var/cache/apt# cd /var/cache/apt/
root@192:/var/cache/apt# du -sh *
111M archives
62M archives.bak
34M pkgcache.bin
34M srcpkgcache.bin
root@192:/var/cache/apt#
对安装包进行打包
zip -r mysql.zip /var/cache/apt/archives/*
存放位置
navicat数据库连接工具
连接我们刚才创建的数据库
出现报错
默认root用户是不允许远程登陆的,创建一个新的用户
mysql> create user aike@'localhost' identified by 'AIke@11..';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to aike@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
步骤2
测试
查看数据库是存在的