[email protected]:/mysql/ rpm qa grep mariadb [email protected]:/mysql/ 创建mysql用户 创建mysql目录 useradd r mysql M s /bin/nologin M 不创建用户的家目录 mk...">

当前位置:网站首页>debian10编译安装mysql

debian10编译安装mysql

2022-07-07 16:00:00 一个运维小青年

debian10编译安装mysql

卸载mariadb
[email protected]:/mysql# rpm -qa | grep mariadb
[email protected]:/mysql# 
创建mysql用户 创建mysql目录
useradd -r mysql -M -s /bin/nologin  

-M 不创建用户的家目录

mkdir -p /usr/local/{
    data,mysql,log}

[email protected]:/usr/local/mysql# mkdir -p /usr/local/mysql/data
[email protected]:/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

image-20220523161929482

安装包位置
image-20220523162025504

安装编译工具

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

直接找包安装

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

image-20220523173400657

俩种解决方法,第一种就是去搜索各种依赖的安装
第二种,就是去安装这些依赖的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  

image-20220523171057715

第二个依赖的问题

openssl-devel 这个依赖

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

image-20220523172228333

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

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gxNCGAwU-1656669229362)(C:%5CUsers%5CIBimFish_001%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20220523172946116.png)]

第四个安装包

aptitude -y install gcc-8
aptitude -y install g++-8

第五个安装包

aptitude -y install  gcc automake autoconf libtool make

第六个安装包

aptitude -y install  libc6-dev

image-20220523174251878

第七个安装包
cmake

安装地址

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

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

image-20220523174745624

下载安装

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

image-20220523180059843

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

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

ls   /var/cache/apt/archives/

image-20220523180251979

解压安装包

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

image-20220523180820615

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

image-20220523181117868

遇到报错image-20220523182603606

尝试解决方法

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

image-20220523212640090

创建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

又出现新的报错
image-20220523214157169

解决方法

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

image-20220523214408695

卸载这个

aptitude remove -y gcc-8-base

从新安装
image-20220523214618042

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

aptitude -y remove libhdf5-dev

image-20220523214959305

完美解决

aptitude -y  install pkg-config

image-20220523224346888

make

image-20220523224650495

成功截图
image-20220524100500987

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        初始化密码

image-20220525134551973

添加环境变量
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

我这里存放位置不一样
image-20220525134919044

修改配置文件
[email protected]:/etc/mysql# cd /etc/mysql/
[email protected]:/etc/mysql# ls
conf.d	mariadb.cnf  mariadb.conf.d  my.cnf  my.cnf.fallback
[email protected]:/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  #刚才保存的

image-20220525135541207

启动数据库
cd /server/mysql/
[email protected]:/server/mysql# ls
bin   docs  include  LICENSE  mysql-test  README-test  support-files
data  etc   lib      man      README	  share        tmp
[email protected]:/server/mysql# ./bin/mysqld_safe --user=mysql &
[2] 11860
[email protected]:/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

image-20220525143430298

设置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='[email protected]'

image-20220525150212520

第二种方式

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

缓存mysql依赖

[email protected]:/var/cache/apt# cd /var/cache/apt/
[email protected]:/var/cache/apt# du -sh *
111M	archives
62M	archives.bak
34M	pkgcache.bin
34M	srcpkgcache.bin
[email protected]:/var/cache/apt# 

image-20220525150556565

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

image-20220525150722733

存放位置

navicat数据库连接工具

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

出现报错
image-20220525151353347

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

mysql> create user [email protected]'localhost' identified by '[email protected]';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to [email protected]'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

image-20220525152915474

步骤2
image-20220525153012933

测试
image-20220525153244133

查看数据库是存在的
image-20220525153326057

mysql离线包安装

显示目录颜色

[[email protected] ~]# apt-get install lrzsz
[[email protected] /]# tail /etc/profile ###显示目录颜色
export LS_OPTIONS='--color=auto'
eval `dircolors`
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

MySQL安装包

[[email protected] local]# ll -h mysql-5.7.17-linux-glibc2.5-x86_64.tar 
-rw-r--r-- 1 zhangya zhangya 652M 627 23:19 mysql-5.7.17-linux-glibc2.5-x86_64.tar
下载安装地址
下边连接:https://www.cnblogs.com/zero-gg/p/8875598.html,大神的结晶啊,我就悄悄的留下来自己用,链接缺少的部分补充下:

1.包的下载方法:wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

安装依赖

[[email protected] local]# apt-cache search libaio #查找依赖包信息
[[email protected] local]# apt-get install libaio1 # install library #安装依赖包

添加mysql组

[root@mysql-193 local]# groupadd mysql

添加mysql用户并且禁止登录

[root@mysql-193 local]# useradd -r -g mysql -s /bin/false mysql

创建数据库目录

[root@mysql-193 mysql]# mkdir -p /data/mysql_data

解压mysql安装包

[root@mysql-193 local]# cd /usr/local
[root@mysql-193 local]# tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

创建软链接

[root@mysql-193 local]# ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 mysql

查看创建结果

[root@mysql-193 local]# ll mysql
lrwxrwxrwx 1 root staff 45 627 23:58 mysql -> /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64

修改mysql目录的权限以及所属用户及组属性相关(官网)

[root@mysql-193 local]# cd mysql
[root@mysql-193 mysql]# mkdir mysql-files
[root@mysql-193 mysql]# chmod 750 mysql-files
[root@mysql-193 mysql]# chown -R mysql . ##只修改文件属主
[root@mysql-193 mysql]# chgrp -R mysql . #修改文件属组

初始化数据库

#注意! 5.7版本以后的初始化命令和5.6有区别
#使用老命令初始化的报错内容如
[[email protected]-193 mysql]# bin/mysql_install_db --user=mysql 
2017-06-28 00:10:11 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-06-28 00:10:11 [ERROR]   The data directory needs to be specified.
#使用新的初始化命令
[[email protected]-193 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

注意, 这里最后一行最后面会提示一个字符串,这个是mysql5.7以后的安全策略,会生成一个root的随机密码

......
2017-06-27T16:14:05.150862Z 1 [Note] A temporary password is generated for [email protected]localhost: 1Diwj2r(pN-k

把目录所属者权限修改回root

[root@mysql-193 mysql]# chown -R root .

修改数据库目录的所属者为mysql

[root@mysql-193 mysql]# chown -R mysql /data/
[root@mysql-193 mysql]# ll /data/
drwxr-xr-x 5 mysql mysql 4096 628 00:14 mysql_data

拷贝复制配置文件到/etc/my.cnf

 [root@mysql-193 mysql]# grep -v "^#" support-files/my-default.cnf >/data/mysql_data/my.cnf

修改配置文件

[root@mysql-193 mysql]# vim /data/mysql_data/my.cnf
[root@mysql-193 mysql]# cat /data/mysql_data/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql_data
port = 3306  
socket = /tmp/mysql.sock  
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

启动mysql服务

[[email protected]mysql-193 mysql]# bin/mysqld_safe --defaults-file=/data/mysql_data/my.cnf --user=mysql --pid-file=/data/mysql_data/mysqld_safe.pid --log-error=/data/mysql_data/mysql.err.log &

查看进程

[root@mysql-193 ~]# ps -ef|grep mysqld
root       3113    775  0 00:59 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql_data/my.cnf --user=mysql --pid-file=/data/mysql_data/mysqld_safe.pid --log-error=/data/mysql_data/mysql.err.log

mysql      3287   3113  0 00:59 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql_data/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql_data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql_data/mysql.err.log --pid-file=/data/mysql_data/mysqld_safe.pid --socket=/tmp/mysql.sock --port=3306



root       3333   1275  0 01:00 pts/1    00:00:00 grep mysqld

将mysql命令加入环境变量

[root@mysql-193 ~]# tail -2 /etc/profile
PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin
[root@mysql-193 ~]# source /etc/profile

再次输入mysql发现已经可以补全了

[root@mysql-193 ~]# mysql

登录数据库

[root@mysql-193 ~]# mysql -uroot -p'1Diwj2r(pN-k'

这时使用命令会提示需要修改密码,所以这里修改数据库默认密码

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'goumin123';
Query OK, 0 rows affected (0.00 sec)
mysql>exit 

使用新密码登录

[root@mysql-193 ~]# mysql -uroot -p'goumin123'
mysql>
解决报错

解决

mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc
sudo apt install libncurses5

202服务器mysql密码
Adu#jaJ.r2l,

image-20220701145747561

脚本文件一键安装

[[email protected] ~]# cat 101.sh 
 
#下载依赖包
apt-get install libaio1
apt-get install lrzsz
 
#添加mysql用户和组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
 
#创建mysql数据目录
mkdir -p /data/mysql_data
 
#解压mysqltar包
cd /usr/local
tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar
rm -f mysql-5.7.17-linux-glibc2.5-x86_64.tar mysql-test-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
 
#创建软连接
ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 mysql
 
#修改mysql目录权限和创建文件
cd /usr/local
cd mysql
mkdir mysql-files
chmod 750 mysql-files
chown -R mysql:mysql .
 
#初始化mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data >/tmp/mima.txt 2>&1
 
#修改mysql软件目录权限
chown -R root.staff /usr/local/mysql
 
#修改mysql数据目录权限
chown -R mysql.mysql /data/
 
#拷贝配置文件
cd /usr/local
cd mysql
grep -v "^#" support-files/my-default.cnf >/data/mysql_data/my.cnf
 
#修改配置文件
cat>/data/mysql_data/my.cnf<<EOF [mysqld] basedir = /usr/local/mysql datadir = /data/mysql_data port = 3306 socket = /tmp/mysql.sock sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES EOF
 
 
#将mysql命令加入环境变量
echo 'PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin' >> /etc/profile
 
#启动mysql服务
bin/mysqld_safe --defaults-file=/data/mysql_data/my.cnf --user=mysql --pid-file=/data/mysql_data/mysqld_safe.pid --log-error=/data/mysql_data/mysql.err.log & 

alize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data >/tmp/mima.txt 2>&1

#修改mysql软件目录权限
chown -R root.staff /usr/local/mysql

#修改mysql数据目录权限
chown -R mysql.mysql /data/

#拷贝配置文件
cd /usr/local
cd mysql
grep -v “^#” support-files/my-default.cnf >/data/mysql_data/my.cnf

#修改配置文件
cat>/data/mysql_data/my.cnf<<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql_data
port = 3306
socket = /tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
EOF

#将mysql命令加入环境变量
echo ‘PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin’ >> /etc/profile

#启动mysql服务
bin/mysqld_safe --defaults-file=/data/mysql_data/my.cnf --user=mysql --pid-file=/data/mysql_data/mysqld_safe.pid --log-error=/data/mysql_data/mysql.err.log &


原网站

版权声明
本文为[一个运维小青年]所创,转载请带上原文链接,感谢
https://blog.csdn.net/tianmingqing0806/article/details/125563477