Database _mysql installation

Install mysql in binary

Operating system: Linux centos7 Installation version: mysql-5.7.21
Download address: wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar .gz

1. Install the dependency package
yum install autoconf libaio libaio-devel -y

2. Create groups and users
groupadd mysql; useradd -r -g mysql -s /bin/false mysql

3. Create directory and authorization
[root@centos7_3 data]# mkdir /usr/local/mysql
[root@centos7_3 data]# pwd
/data
[root@centos7_3 data]# ls
mysql-5.7.21-linux-glibc2.12- x86_64.tar.gz
[root@centos7_3 data]# tar xvf mysql-5.7.21-linux-glibc2.12-x86_64
[root@centos7_3 data]# cd /data/mysql-5.6.40-linux-glibc2.12- x86_64
[root@centos7_3 data]# cp -r * /usr/local/mysql/

[root@centos7_3 data]#mkdir /var/lib/mysql
[root@centos7_3 data]#mkdir /usr/local/mysql/{log,data}
[root@centos7_3 data]#chown -R mysql:mysql /var/lib/mysql
[root@centos7_3 data]#chown -R mysql:mysql /usr/local/mysql

4. Add the environment variable
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile ;source /etc/profile

5. Modify the parameter file
vim /etc/my.cnf
[mysql]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock

[mysqld]
port = 3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
character-set-server=utf8mb4
default-storage-engine=INNODB
innodb_buffer_pool_size = 200M
max_allowed_packet=128M
explicit_defaults_for_timestamp=1
log-output=FILE

slow_query_log = ON
slow_query_log_file=/usr/local/mysql/log/liandodb_query.err
long_query_time=5
log-error=/usr/local/mysql/log/liandodb_error.err
default-authentication-plugin=mysql_native_password
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
wait_timeout=31536000
interactive_timeout=31536000
default-time_zone = '+8:00'
max_connections=15000
max_connect_errors = 1000
server-id = 1
log_bin = mysql-bin

6.Database initialization
cd /usr/local/mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql /data/

View the initial password: cat /usr/local/mysql/log/liandodb_error.err |grep root

image_thumb11

7.配置mysql服务
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=
http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536
8.启动mysql
systemctl daemon-reload
systemctl start mysqld
systemctl status mysqld

9. Use the database
mysql -uroot -pefM0GruzV0=<
Modify user password:
ALTER USER'root '@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
flush privileges;

Create user and authorization
create USER'test'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
grant all privileges on *.* to'test '@'%' with grant option;
flush privileges;

Install mariadb in binary

Operating system: Linux centos7 Installation version: mariadb-10.2.25
1. Create user and database installation directory
useradd -r -s /sbin/nologin -d /data/mysql mysql 
mkdir /data/mysql

2. Decompression and authorization
[root@centos7_2 data]# tar xvf mariadb-10.2.25-linux-x86_64.tar.gz -C /usr/local/
[root@centos7_2 local]# pwd
/usr/local
[root@centos7_2 local]# ln -s mariadb-10.2.25-linux-x86_64/ mysql
soft link modification authority must add "/"
[root@centos7_2 local]# chown -R root.root mysql/

3. Create the database
[root@centos7_2 scripts]# pwd
/usr/local/mysql/scripts
[root@centos7_2 scripts]# ls
mysql_install_db
#mysql_install_db The script used to create the database
[root@centos7_2 mysql]# pwd
/usr/local/ mysql
[root@centos7_2 mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql #must be run under /usr/local/mysql

4.配置文件
[root@centos7_2 support-files]# pwd
/usr/local/mysql/support-files
[root@centos7_2 support-files]# ls
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
magic             my-large.cnf            mysqld_multi.server  policy
my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf
[root@centos7_2 support-files]# mkdir /etc/mysql 
[root@centos7_2 support-files]# cp my-huge.cnf  /etc/mysql/my.cnf
[root@centos7_2 support-files]# vim /etc/mysql/my.cnf

image

[root@centos7_2 support-files]# cp mysql.server  /etc/init.d/mysqld
[root@centos7_2 support-files]# chkconfig --add mysqld

5. Start the service
[root@centos7_2 support-files]# service mysqld start
Starting mysqld (via systemctl): [OK]

6. Environment variable configuration
[root@centos7_2 support-files]# echo'PATH=/usr/local/mysql/bin:$PATH'> /etc/profile.d/mysql.sh
[root@centos7_2 support-files]# . /etc/profile.d/mysql.sh

7.安全加固
[root@centos7_2 bin]# ll /usr/local/mysql/bin/|grep mysql_secure_installation
-rwxr-xr-x 1 root root     12551 Jun 15  2019 mysql_secure_installation
[root@centos7_2 bin]# mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Compile and install mariadb from source code

操作系统:Linux centos7     安装版本:mariadb-10.2.25
[root@centos7_3 ~]# fdisk -l
[root@centos7_3 ~]# lsblk
一、逻辑卷
1.分区
[root@centos7_3 ~]# fdisk /dev/sda
Command (m for help): p
Command (m for help): n
First sector (325066752-419430399, default 325066752):
Using default value 325066752
Last sector, +sectors or +size{K,M,G} (325066752-419430399, default 419430399):
Using default value 419430399
Partition 7 of type Linux and of size 45 GiB is set
Command (m for help): t
Partition number (1-7, default 7):
Hex code (type L to list all codes): L
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
同步
[root@centos7_3 ~]# partprobe

Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

2. Create a physical volume
[root@centos7_3 ~]# pvcreate /dev/sda7
  Physical volume "/dev/sda7" successfully created.
View:
[root@centos7_3 ~]# pvs
  PV VG Fmt Attr PSize PFree 
  /dev/sda7 lvm2- - <45.00g <45.00g

3.创建卷组
[root@centos7_3 ~]# vgcreate vg0 /dev/sda7 -s 16M
  Volume group "vg0" successfully created
查看:
[root@centos7_3 ~]# vgs
  VG  #PV #LV #SN Attr   VSize  VFree
  vg0   1   0   0 wz--n- 44.98g 44.98g
[root@centos7_3 ~]# vgdisplay

4. Create logical volume
[root@centos7_3 ~]# lvcreate -n mysql -l 100%free vg0
  Logical volume "mysql" created.
View:
[root@centos7_3 ~]# lvdisplay

5.格式化及挂载到目录
[root@centos7_3 ~]# mkdir /data/mysql
[root@centos7_3 ~]# mkfs.xfs /dev/vg0/mysql   #格式化
[root@centos7_3 ~]# blkid
/dev/sda2: UUID="bea8621e-86ea-4547-b573-908acf67670a" TYPE="xfs"
/dev/sda1: UUID="e92bf162-5d64-46be-be3a-7a7e69344ad3" TYPE="xfs"
/dev/sda3: UUID="09e0e953-b6a0-4fcb-8881-3dbf139d659b" TYPE="xfs"
/dev/sda5: UUID="a5a9c73e-f6c4-4b7e-800a-2bdec4b878fe" TYPE="swap"
/dev/sda7: UUID="qyb1H0-ecZk-eBvL-T8S9-QOhj-2LnA-dNsX8a" TYPE="LVM2_member"
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/vg0-mysql: UUID="a0dd2c70-19fc-4a5f-95db-f036cd0fc795" TYPE="xfs"
[root@centos7_3 ~]# vim /etc/fstab

image

[root@centos7_3 ~]# mount -a
[root@centos7_3 ~]# df –h

image

2. Database installation
1. Create user and authorization
[root@centos7_3 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@centos7_3 ~]# chown mysql.mysql /data/mysql/

2.安装包:
[root@centos7_3 ~]# yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel libdb-cxx-devel -y 

[root@centos7_3 data]# tar xvf mariadb-10.2.25.tar.gz
[root@centos7_3 data]# cd mariadb-10.2.25/
3.编译:
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
If you want to recompile, you need to delete the CMakeCache.txt file
   rm -f CMakeCache.txt
4. Install
make -j 4 && make install && echo -e'\a' &&date

5. Prepare environment variable
echo'PATH=/app/mysql/bin:$PATH'> /etc/profile.d/mysql.sh
. /Etc/profile.d/mysql.sh
6. Generate database file
cd /app/ mysql/
scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
7. Prepare the configuration file
cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
vim /etc/my .cnf
datadir=/data/mysql
8. Prepare the startup script
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
9. Start the service
chkconfig --add mysqld
chkconfig --list
systemctl start mysqld

Guess you like

Origin blog.51cto.com/14814545/2667558