[email protected]:/mysql/ rpm qa grep mariadb [email protected]:/mysql/ establish mysql user establis...">

当前位置:网站首页>Debian10 compile and install MySQL

Debian10 compile and install MySQL

2022-07-07 18:08:00 An operation and maintenance young man

debian10 Compilation and installation mysql

uninstall mariadb
[email protected]:/mysql# rpm -qa | grep mariadb
[email protected]:/mysql# 
establish mysql user establish mysql Catalog
useradd -r mysql -M -s /bin/nologin  

-M Do not create the user's home directory

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

Download the installation package from the official website

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

image-20220523161929482

Installation package location
image-20220523162025504

Install the compiler

Because this is debian10 operating system , Follow centos The operating system is a little different , It's too troublesome to install these dependencies directly ,

Directly find the package and install

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

image-20220523173400657

Two solutions , The first is to search for various dependent installations
The second kind , Is to install these dependencies 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   # The dependence needed 

The first problem of dependence
ncurses ncurses-devel This dependence

aptitude -y install libncurses5-dev  

image-20220523171057715

The second problem of dependence

openssl-devel This dependence

aptitude -y install   libssl-dev   # Install this first 
aptitude -y install   openssl      # Then install this 

image-20220523172228333

The third installation package
gcc gcc-c++ This

aptitude install -y bison   # Just install it directly 

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-gxNCGAwU-1656669229362)(C:%5CUsers%5CIBimFish_001%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20220523172946116.png)]

The fourth installation package

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

The fifth installation package

aptitude -y install  gcc automake autoconf libtool make

The sixth installation package

aptitude -y install  libc6-dev

image-20220523174251878

The seventh installation package
cmake

Installation address

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

We choose to download the version that can be used directly , Right click to save the link address , open Linux System ( With Ubuntu For example )

image-20220523174745624

Download and install

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

decompression

tar -zxvf cmake-3.5.2-Linux-x86_64.tar.gz
mv cmake-3.5.2-Linux-x86_64 cmake
vim /etc/profile   # Add environment variables 

export CMAKE_HOME=/mysql/cmake/bin
export PATH=$CMAKE_HOME:$PATH

Save and exit , Refresh environment variable

source /etc/profile

Verify successful installation

cmake -version

image-20220523180059843

Check whether these dependencies are installed

With the following dependencies , Can be compressed and packaged to other servers for direct installation

ls   /var/cache/apt/archives/

image-20220523180251979

Unzip the installation package

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

image-20220523180820615

mv mysql-5.7.27 mysql  # Move and change the name 
cd  /usr/local/mysql

compile , I made a mistake here

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

In case of an error image-20220523182603606

Try a solution

aptitude -y  install libgmp-dev

aptitude -y  install flex

 Not solve  #

Try a new installation mysql

cd  /etc/apt/

vim /etc/apt//sources.list   # Backup first 
#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

establish mysql Catalog
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
 
download mysql Installation package
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

compile
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

There are new misstatements
image-20220523214157169

resolvent

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

image-20220523214408695

Uninstall this

aptitude remove -y gcc-8-base

Install from New
image-20220523214618042

These two are still different , Not the uninstall we want to install

aptitude -y remove libhdf5-dev

image-20220523214959305

Perfect solution

aptitude -y  install pkg-config

image-20220523224346888

make

image-20220523224650495

Screenshot of success
image-20220524100500987

make install
chown -R mysql:mysql /server/mysql
 
cd /server/mysql
 
# Generate temporary password , To save it 
bin/mysqld --initialize --user=mysql --basedir=/server/mysql/ --datadir=/server/mysql/data/


>K,>Nkdyv2p8         Initialize password 

image-20220525134551973

Add environment variables
vim /etc/profile  Environment variables are in the last line of this file 
PATH=/usr/local/mysql/bin:$PATH  The last line 
[root mysql]# source /etc/profile  Restart it   Environment variables file 
[roott mysql]# echo $PATH  Check whether it is loaded 
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
7

My storage location is different
image-20220525134919044

Modify the configuration file
[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 # Backup first 
vim my.cnf

Insert the code

[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 # Just saved 
pid-file=/server/mysql/data/i-qluq9hly.pid  # Just saved 

image-20220525135541207

Start database
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]+   Completed                ./bin/mysqld_safe --user=mysql

image-20220525143430298

Set up MySQL start-up Restart the loading service

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
Change Password

The first way to change the password

set password='[email protected]'

image-20220525150212520

The second way

mysqladmin -u root -p’ Old password ’ password  ‘ New password ’

cache mysql rely on

[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

Package the installation package
zip -r  mysql.zip /var/cache/apt/archives/*

image-20220525150722733

Storage location

navicat Database connection tools

Connect to the database we just created

There is an error
image-20220525151353347

Default root Users are not allowed to log in remotely , Create a new user

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

step 2
image-20220525153012933

test
image-20220525153244133

Check that the database exists
image-20220525153326057

mysql Offline package installation

Show directory colors

[[email protected] ~]# apt-get install lrzsz
[[email protected] /]# tail /etc/profile ### Show directory colors 
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 Installation package

[[email protected] local]# ll -h mysql-5.7.17-linux-glibc2.5-x86_64.tar 
-rw-r--r-- 1 zhangya zhangya 652M 6 month   27 23:19 mysql-5.7.17-linux-glibc2.5-x86_64.tar
Download the installation address
 Bottom connection :https://www.cnblogs.com/zero-gg/p/8875598.html, The crystallization of the great God , I will quietly stay for my own use , The missing part of the link is added :

1. Download method of package :wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

Installation dependency

[[email protected] local]# apt-cache search libaio # Find dependent package information 
[[email protected] local]# apt-get install libaio1 # install library # Install dependency packages 

add to mysql Group

[root@mysql-193 local]# groupadd mysql

add to mysql Users are not allowed to log in

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

Create database directory

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

decompression mysql Installation package

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

Create soft link

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

View the creation results

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

modify mysql The permissions of the directory and the attributes of the user and group are related ( Official website )

[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 . ## Only modify the file owner 
[root@mysql-193 mysql]# chgrp -R mysql . # Modify file belongs to group 

Initialize database

# Be careful ! 5.7 Initialization commands after version and 5.6 There's a difference 
# The error content initialized with the old command is as follows 
[[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.
# Use the new initialization command 
[[email protected]-193 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

Be careful , There will be a string at the end of the last line , This is mysql5.7 Future security strategies , Will generate a root Random password of

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

Modify the permission of the directory owner back to root

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

Modify the owner of the database directory to mysql

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

Copy the copy configuration file to /etc/my.cnf

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

Modify the configuration file

[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

start-up mysql service

[[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 &

Check the process

[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

take mysql Command to add environment variables

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

Input again mysql It is found that it can be completed

[root@mysql-193 ~]# mysql

Log in to the database

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

At this time, the command will prompt you to change the password , So change the default password of the database here

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 

Log in with the new password

[root@mysql-193 ~]# mysql -uroot -p'goumin123'
mysql>
Resolve errors

solve

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

202 The server mysql password
Adu#jaJ.r2l,

image-20220701145747561

Script file one click installation

[[email protected] ~]# cat 101.sh 
 
# Download dependency package 
apt-get install libaio1
apt-get install lrzsz
 
# add to mysql Users and groups 
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
 
# establish mysql Data directory 
mkdir -p /data/mysql_data
 
# decompression mysqltar package 
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
 
# Create a soft connection 
ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 mysql
 
# modify mysql Directory permissions and create files 
cd /usr/local
cd mysql
mkdir mysql-files
chmod 750 mysql-files
chown -R mysql:mysql .
 
# initialization mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data >/tmp/mima.txt 2>&1
 
# modify mysql Software directory permissions 
chown -R root.staff /usr/local/mysql
 
# modify mysql Data directory permissions 
chown -R mysql.mysql /data/
 
# Copy configuration file 
cd /usr/local
cd mysql
grep -v "^#" support-files/my-default.cnf >/data/mysql_data/my.cnf
 
# Modify the configuration file 
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
 
 
# take mysql Command to add environment variables 
echo 'PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin' >> /etc/profile
 
# start-up mysql service 
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

# modify mysql Software directory permissions
chown -R root.staff /usr/local/mysql

# modify mysql Data directory permissions
chown -R mysql.mysql /data/

# Copy configuration file
cd /usr/local
cd mysql
grep -v “^#” support-files/my-default.cnf >/data/mysql_data/my.cnf

# Modify the configuration file
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

# take mysql Command to add environment variables
echo ‘PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin’ >> /etc/profile

# start-up mysql service
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 &


原网站

版权声明
本文为[An operation and maintenance young man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071559582186.html