debian10编译安装mysql

卸载mariadb
  1. root@192:/mysql# rpm -qa | grep mariadb
  2. root@192:/mysql#

创建mysql用户 创建mysql目录
  1. useradd -r mysql -M -s /bin/nologin

-M 不创建用户的家目录

  1. mkdir -p /usr/local/{data,mysql,log}
  2. root@192:/usr/local/mysql# mkdir -p /usr/local/mysql/data
  3. root@192:/usr/local/mysql# mkdir -p /usr/share/man

从官网下载安装包

  1. wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz

debian10编译安装mysql - 图1

安装包位置
debian10编译安装mysql - 图2

安装编译工具

因为我这是debian10操作系统,跟centos操作系统有点不一样,比较麻烦没办法直接安装这些依赖,

直接找包安装

  1. https://www.debian.org/distrib/packages

debian10编译安装mysql - 图3

俩种解决方法,第一种就是去搜索各种依赖的安装
第二种,就是去安装这些依赖的tar.gz

  1. https://blog.csdn.net/weixin_45191791/article/details/110136458
  1. aptitude -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf cmake #所需要的依赖

第一个依赖的问题
ncurses ncurses-devel 这个依赖

  1. aptitude -y install libncurses5-dev

debian10编译安装mysql - 图4

第二个依赖的问题

openssl-devel 这个依赖

  1. aptitude -y install libssl-dev #先安装这个
  2. aptitude -y install openssl #再安装这个

debian10编译安装mysql - 图5

第三个安装包
gcc gcc-c++这个

  1. aptitude install -y bison #直接安装就好

第四个安装包

  1. aptitude -y install gcc-8
  2. aptitude -y install g++-8

第五个安装包

  1. aptitude -y install gcc automake autoconf libtool make

第六个安装包

  1. aptitude -y install libc6-dev

debian10编译安装mysql - 图6

第七个安装包
cmake

安装地址

  1. https://cmake.org/files/v3.5/

我们选择下载直接可以使用的版本,右键保存链接地址,打开Linux系统(以Ubuntu为例)

debian10编译安装mysql - 图7

下载安装

  1. wget -c https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz

解压

  1. tar -zxvf cmake-3.5.2-Linux-x86_64.tar.gz
  2. mv cmake-3.5.2-Linux-x86_64 cmake
  3. vim /etc/profile #添加环境变量
  4. export CMAKE_HOME=/mysql/cmake/bin
  5. export PATH=$CMAKE_HOME:$PATH

保存退出,刷新环境变量

  1. source /etc/profile

检验是否安装成功

  1. cmake -version

debian10编译安装mysql - 图8

查看一下这些依赖有没有安装好

有了下面这些依赖,都可以压缩打包到其他服务器上面直接安装了

  1. ls /var/cache/apt/archives/

debian10编译安装mysql - 图9

解压安装包

  1. tar -zxvf mysql-boost-5.7.27.tar.gz -C /usr/local/

debian10编译安装mysql - 图10

  1. mv mysql-5.7.27 mysql #移动改名称
  2. cd /usr/local/mysql

编译,我这里报错了

  1. cmake .
  2. -DWITH_BOOST=boost/boost_1_59_0/
  3. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
  4. -DSYSCONFDIR=/etc
  5. -DMYSQL_DATADIR=/usr/local/mysql/data
  6. -DINSTALL_MANDIR=/usr/share/man
  7. -DMYSQL_TCP_PORT=3306
  8. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
  9. -DDEFAULT_CHARSET=utf8
  10. -DEXTRA_CHARSETS=all
  11. -DDEFAULT_COLLATION=utf8_general_ci
  12. -DWITH_READLINE=1
  13. -DWITH_SSL=system
  14. -DWITH_EMBEDDED_SERVER=1
  15. -DENABLED_LOCAL_INFILE=1
  16. -DWITH_INNOBASE_STORAGE_ENGINE=1

debian10编译安装mysql - 图11

遇到报错debian10编译安装mysql - 图12

尝试解决方法

  1. aptitude -y install libgmp-dev
  2. aptitude -y install flex
  3. 解决不了 #

尝试新的安装mysql

  1. cd /etc/apt/
  2. vim /etc/apt//sources.list #先备份
  3. #Ctrl+Insert :wq
  4. deb http://mirrors.163.com/debian/ buster main non-free contrib
  5. deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
  6. deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
  7. deb-src http://mirrors.163.com/debian/ buster main non-free contrib
  8. deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
  9. deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib
  10. deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
  11. deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
  12. apt update
  13. aptitude install -y binutils build-essential cmake gawk bison flex texinfo automake autoconf libtool cvs libncurses5-dev libglib2.0-dev gettext intltool subversion

debian10编译安装mysql - 图13

创建mysql目录
  1. mkdir /ok
  2. cd /ok
  3. apt install -y openssl libssl-dev
  4. useradd -s /sbin/nologin mysql
  5. mkdir /server/
  6. mkdir /server/mysql
  7. mkdir /server/mysql/data
  8. mkdir /server/mysql/etc
  9. mkdir /server/mysql/tmp

下载mysql安装包
  1. wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.35.tar.gz
  2. tar -zxvf ./mysql-boost-5.7.35.tar.gz
  3. cd ./mysql-boost-5.7.35

编译
  1. 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

又出现新的报错
debian10编译安装mysql - 图14

解决方法

  1. aptitude -y install libhdf5-serial-dev hdf5-tools

debian10编译安装mysql - 图15

卸载这个

  1. aptitude remove -y gcc-8-base

从新安装
debian10编译安装mysql - 图16

这俩个还是不一样,不是咱们想安装的卸载

  1. aptitude -y remove libhdf5-dev

debian10编译安装mysql - 图17

完美解决

  1. aptitude -y install pkg-config

debian10编译安装mysql - 图18

  1. make

debian10编译安装mysql - 图19

成功截图
debian10编译安装mysql - 图20

  1. make install
  1. chown -R mysql:mysql /server/mysql
  2. cd /server/mysql
  3. #生成临时密码,要保存下来
  4. bin/mysqld --initialize --user=mysql --basedir=/server/mysql/ --datadir=/server/mysql/data/
  5. >K,>Nkdyv2p8 初始化密码

debian10编译安装mysql - 图21

添加环境变量
  1. vim /etc/profile 环境变量都在这个文件里面最后一行
  2. PATH=/usr/local/mysql/bin:$PATH 最后一行
  3. [root mysql]# source /etc/profile 重启一下 环境变量文件
  4. [roott mysql]# echo $PATH 查看一下有没有加载上
  5. /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  6. 7

我这里存放位置不一样
debian10编译安装mysql - 图22

修改配置文件
  1. root@192:/etc/mysql# cd /etc/mysql/
  2. root@192:/etc/mysql# ls
  3. conf.d mariadb.cnf mariadb.conf.d my.cnf my.cnf.fallback
  4. root@192:/etc/mysql# cp my.cnf my.cnf_bak #优先备份一下
  5. vim my.cnf

插入一下代码

  1. [client]
  2. port=3306
  3. socket=/server/mysql/tmp/mysql.sock
  4. default-character-set = utf8
  5. [mysqld]
  6. port=3306
  7. bind-address=127.0.0.1
  8. basedir=/server/mysql
  9. datadir=/server/mysql/data
  10. socket=/server/mysql/tmp/mysql.sock
  11. user=mysql
  12. # Disabling symbolic-links is recommended to prevent assorted security risks
  13. symbolic-links=0
  14. # time zone
  15. default-time-zone = system
  16. character-set-server = utf8
  17. default-storage-engine = InnoDB
  18. [mysqld_safe]
  19. log-error=/server/mysql/data/i-qluq9hly.err #刚才保存的
  20. pid-file=/server/mysql/data/i-qluq9hly.pid #刚才保存的

debian10编译安装mysql - 图23

启动数据库
  1. cd /server/mysql/
  2. root@192:/server/mysql# ls
  3. bin docs include LICENSE mysql-test README-test support-files
  4. data etc lib man README share tmp
  5. root@192:/server/mysql# ./bin/mysqld_safe --user=mysql &
  6. [2] 11860
  7. root@192:/server/mysql# Logging to '/server/mysql/data/i-qluq9hly.err'.
  8. 2022-05-25T05:58:06.598996Z mysqld_safe Starting mysqld daemon with databases from /server/mysql/data
  9. 2022-05-25T05:58:08.534790Z mysqld_safe mysqld from pid file /server/mysql/data/i-qluq9hly.pid ended
  10. [2]+ 已完成 ./bin/mysqld_safe --user=mysql

debian10编译安装mysql - 图24

设置MySQL 启动 重启加载服务
  1. cp support-files/mysql.server /etc/init.d/mysql
  2. cp bin/mysqld /etc/init.d/
  3. chmod +x /etc/init.d/mysql
  4. update-rc.d mysql defaults
  5. service mysql start
  6. cp bin/mysql /usr/bin/mysql
  7. chmod +x /usr/bin/mysql
  8. mysql -uroot -p
  9. ALTER USER 'root'@'localhost' IDENTIFIED BY 'OkPlus123456' PASSWORD EXPIRE NEVER;
  10. flush privileges;
  11. service mysqld stop

修改密码

修改密码第一种方式

  1. set password='BImuyu@11..'

debian10编译安装mysql - 图25

第二种方式

  1. mysqladmin -u root -p’旧密码’ password ‘新密码’

缓存mysql依赖

  1. root@192:/var/cache/apt# cd /var/cache/apt/
  2. root@192:/var/cache/apt# du -sh *
  3. 111M archives
  4. 62M archives.bak
  5. 34M pkgcache.bin
  6. 34M srcpkgcache.bin
  7. root@192:/var/cache/apt#

debian10编译安装mysql - 图26

对安装包进行打包
  1. zip -r mysql.zip /var/cache/apt/archives/*

debian10编译安装mysql - 图27

存放位置
debian10编译安装mysql - 图28

navicat数据库连接工具

连接我们刚才创建的数据库

出现报错
debian10编译安装mysql - 图29

默认root用户是不允许远程登陆的,创建一个新的用户

  1. mysql> create user aike@'localhost' identified by 'AIke@11..';
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> grant all on *.* to aike@'localhost';
  6. Query OK, 0 rows affected (0.01 sec)
  7. mysql> flush privileges;
  8. Query OK, 0 rows affected (0.00 sec)
  9. mysql>

debian10编译安装mysql - 图30

步骤2
debian10编译安装mysql - 图31

测试
debian10编译安装mysql - 图32

查看数据库是存在的
debian10编译安装mysql - 图33