Linux、centos通用二进制格式安装MySQL数据库

一、下载官方安装包和依赖包

官网选择包https://downloads.mysql.com/archives/community/
在这里插入图片描述

[11:45:41 root@yp mysql] yum -y install libaio perl-Data-Dumper autoconf lvm2 ncurses-compat-libs 

二、创建用户和组

groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 -d /data/mysql mysql 

三、准备目录(建议使用逻辑卷,方便扩容)

[10:31:09 root@yp ~] lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    2G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0   50G  0 part /data
sr0     11:0    1  6.7G  0 rom

# 创建逻辑卷
[10:38:56 root@yp ~]#fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1f83e643

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048   4196351   4194304    2G 83 Linux
/dev/sda2         4196352 213911551 209715200  100G 83 Linux
/dev/sda3       213911552 218105855   4194304    2G 82 Linux swap / Solaris
/dev/sda4       218105856 419430399 201324544   96G  5 Extended
/dev/sda5       218107904 322965503 104857600   50G 83 Linux

Command (m for help): n
All primary partitions are in use.
Adding logical partition 6
First sector (322967552-419430399, default 322967552):
Last sector, +sectors or +size{
    
    K,M,G,T,P} (322967552-419430399, default 419430399): +30G

Created a new partition 6 of type 'Linux' and of size 30 GiB.

Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1f83e643

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048   4196351   4194304    2G 83 Linux
/dev/sda2         4196352 213911551 209715200  100G 83 Linux
/dev/sda3       213911552 218105855   4194304    2G 82 Linux swap / Solaris
/dev/sda4       218105856 419430399 201324544   96G  5 Extended
/dev/sda5       218107904 322965503 104857600   50G 83 Linux
/dev/sda6       322967552 385882111  62914560   30G 83 Linux

Command (m for help): t
Partition number (1-6, default 6):
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1f83e643

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048   4196351   4194304    2G 83 Linux
/dev/sda2         4196352 213911551 209715200  100G 83 Linux
/dev/sda3       213911552 218105855   4194304    2G 82 Linux swap / Solaris
/dev/sda4       218105856 419430399 201324544   96G  5 Extended
/dev/sda5       218107904 322965503 104857600   50G 83 Linux
/dev/sda6       322967552 385882111  62914560   30G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Syncing disks.


[10:41:20 root@yp ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    2G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part
├─sda5   8:5    0   50G  0 part /data
└─sda6   8:6    0   30G  0 part
sr0     11:0    1  6.7G  0 rom

改为物理卷并改名

[10:41:24 root@yp ~] pvcreate /dev/sda6
[10:41:24 root@yp ~] vgcreate vg0 /dev/sda6

创建逻辑卷百分百使用空间

[10:41:24 root@yp ~] lvcreate -n mysql -l 100%free vg0
[10:52:24 root@yp ~]lvs
  LV    VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mysql vg0 -wi-a----- <30.00g

创建文件系统

[10:53:46 root@yp ~] mkfs.ext4 /dev/vg0/mysql
mke2fs 1.44.3 (10-July-2018)
/dev/vg0/mysql contains a ext4 file system
	created on Tue Sep 22 10:53:38 2020
Proceed anyway? (y,N) y
Creating filesystem with 7863296 4k blocks and 1966080 inodes
Filesystem UUID: 067f58b0-2cb4-44ee-b0b5-47c09606c4b3
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

持久保存挂载

[10:53:46 root@yp ~] blkid /dev/vg0/mysql
[10:53:46 root@yp ~] vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Aug 13 17:23:08 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f198db62-985b-46b9-bc19-9a762da1f5bd /                       xfs     defaults        0 0
UUID=6c095799-00b1-4151-82d8-cfe54e79949c /boot                   ext4    defaults        1 2
UUID=5ed8a664-ac3b-4bf1-8011-ed795e6de26b /data                   xfs     defaults        0 0
UUID=95fa678a-9d8a-4847-a51f-f1cb7062a13f swap                    swap    defaults        0 0
UUID=067f58b0-2cb4-44ee-b0b5-47c09606c4b3 /data/mysql             ext4    defaults        0 0

[11:01:10 root@yp ~] mkdir /data/mysql
[11:01:16 root@yp ~] mount -a
[11:02:01 root@yp ~] df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               385M     0  385M   0% /dev
tmpfs                  400M     0  400M   0% /dev/shm
tmpfs                  400M   11M  389M   3% /run
tmpfs                  400M     0  400M   0% /sys/fs/cgroup
/dev/sda2              100G  3.4G   97G   4% /
/dev/sda5               50G  390M   50G   1% /data
/dev/sda1              2.0G  123M  1.7G   7% /boot
tmpfs                   80M     0   80M   0% /run/user/0
/dev/mapper/vg0-mysql   30G   45M   28G   1% /data/mysql

修改所有者和组

[11:04:29 root@yp ~] ll /data/mysql/
total 16
drwx------. 2 root root 16384 Sep 22 10:54 lost+found
[11:06:41 root@yp ~] chown -R mysql.mysql /data/mysql/
[11:06:52 root@yp ~] ll /data/mysql/
total 16
drwx------. 2 mysql mysql 16384 Sep 22 10:54 lost+found

四、准备程序文件

解压缩

[11:09:07 root@yp ~] tar xvf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

名字必须为mysql才可使用,所以创建软连接

[11:09:33 root@yp ~] cd /usr/local/
[11:09:36 root@yp local] ln -s mysql-5.6.48-linux-glibc2.12-x86_64/ mysql
[11:11:02 root@yp local] ls -l mysql
lrwxrwxrwx. 1 root root 36 Sep 22 11:10 mysql -> mysql-5.6.48-linux-glibc2.12-x86_64/

修改权限文件

[11:11:29 root@yp local] pwd
/usr/local
[11:12:48 root@yp local] chown -R root.root mysql/

五、准备配置文件

[14:59:24 root@yp ~] cp -b /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[14:59:24 root@yp ~] cat >> /etc/my.cnf << EOF
datadir=/data/mysql #定义数据库存放路径
innodb_file_per_table = on 
skip_name_resolve = on #禁止主机名解析,建议使用
EOF

六、创建数据库文件

[14:03:31 root@yp mysql] pwd
/usr/local/mysql
[14:05:15 root@yp mysql] ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MySQL system tables...2020-09-22 14:05:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-22 14:05:19 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-09-22 14:05:19 0 [Note] ./bin/mysqld (mysqld 5.6.48) starting as process 13228 ...
2020-09-22 14:05:19 13228 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-09-22 14:05:19 13228 [Note] InnoDB: The InnoDB memory heap is disabled
2020-09-22 14:05:19 13228 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-09-22 14:05:19 13228 [Note] InnoDB: Memory barrier is not used
2020-09-22 14:05:19 13228 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-09-22 14:05:19 13228 [Note] InnoDB: Using Linux native AIO
2020-09-22 14:05:19 13228 [Note] InnoDB: Using CPU crc32 instructions
2020-09-22 14:05:19 13228 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-09-22 14:05:19 13228 [Note] InnoDB: Completed initialization of buffer pool
2020-09-22 14:05:19 13228 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-09-22 14:05:19 13228 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-09-22 14:05:19 13228 [Note] InnoDB: Database physically writes the file full: wait...
2020-09-22 14:05:19 13228 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-09-22 14:05:19 13228 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-09-22 14:05:19 13228 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-09-22 14:05:19 13228 [Warning] InnoDB: New log files created, LSN=45781
2020-09-22 14:05:19 13228 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-09-22 14:05:19 13228 [Note] InnoDB: Doublewrite buffer created
2020-09-22 14:05:19 13228 [Note] InnoDB: 128 rollback segment(s) are active.
2020-09-22 14:05:19 13228 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-09-22 14:05:19 13228 [Note] InnoDB: Foreign key constraint system tables created
2020-09-22 14:05:19 13228 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-09-22 14:05:19 13228 [Note] InnoDB: Tablespace and datafile system tables created.
2020-09-22 14:05:19 13228 [Note] InnoDB: Waiting for purge to start
2020-09-22 14:05:19 13228 [Note] InnoDB: 5.6.48 started; log sequence number 0
2020-09-22 14:05:19 13228 [Note] RSA private key file not found: /data/mysql//private_key.pem. Some authentication plugins will not work.
2020-09-22 14:05:19 13228 [Note] RSA public key file not found: /data/mysql//public_key.pem. Some authentication plugins will not work.
2020-09-22 14:05:19 13228 [Note] Binlog end
2020-09-22 14:05:19 13228 [Note] InnoDB: FTS optimize thread exiting.
2020-09-22 14:05:19 13228 [Note] InnoDB: Starting shutdown...
2020-09-22 14:05:21 13228 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2020-09-22 14:05:21 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-22 14:05:21 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-09-22 14:05:21 0 [Note] ./bin/mysqld (mysqld 5.6.48) starting as process 13250 ...
2020-09-22 14:05:21 13250 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-09-22 14:05:21 13250 [Note] InnoDB: The InnoDB memory heap is disabled
2020-09-22 14:05:21 13250 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-09-22 14:05:21 13250 [Note] InnoDB: Memory barrier is not used
2020-09-22 14:05:21 13250 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-09-22 14:05:21 13250 [Note] InnoDB: Using Linux native AIO
2020-09-22 14:05:21 13250 [Note] InnoDB: Using CPU crc32 instructions
2020-09-22 14:05:21 13250 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-09-22 14:05:21 13250 [Note] InnoDB: Completed initialization of buffer pool
2020-09-22 14:05:21 13250 [Note] InnoDB: Highest supported file format is Barracuda.
2020-09-22 14:05:21 13250 [Note] InnoDB: 128 rollback segment(s) are active.
2020-09-22 14:05:21 13250 [Note] InnoDB: Waiting for purge to start
2020-09-22 14:05:21 13250 [Note] InnoDB: 5.6.48 started; log sequence number 1625977
2020-09-22 14:05:21 13250 [Note] RSA private key file not found: /data/mysql//private_key.pem. Some authentication plugins will not work.
2020-09-22 14:05:21 13250 [Note] RSA public key file not found: /data/mysql//public_key.pem. Some authentication plugins will not work.
2020-09-22 14:05:21 13250 [Note] Binlog end
2020-09-22 14:05:21 13250 [Note] InnoDB: FTS optimize thread exiting.
2020-09-22 14:05:21 13250 [Note] InnoDB: Starting shutdown...
2020-09-22 14:05:23 13250 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h yp.localdomain password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.

[14:08:42 root@yp mysql] rm -r /data/mysql/lost+found ;ls -l /data/mysql/
rm: remove directory '/data/mysql/lost+found'? y
total 110604
-rw-rw----. 1 mysql mysql 12582912 Sep 22 14:05 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Sep 22 14:05 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Sep 22 14:05 ib_logfile1
drwx------. 2 mysql mysql     4096 Sep 22 14:05 mysql
drwx------. 2 mysql mysql     4096 Sep 22 14:05 performance_schema
drwx------. 2 mysql mysql     4096 Sep 22 14:05 test

七、准备服务脚本并启动

[14:19:13 root@yp] cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[14:22:39 root@yp init.d] service mysqld start

八、添加PATH路径

[14:22:39 root@yp init.d] echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[14:26:12 root@yp init.d] . /etc/profile.d/mysql.sh

九、安全初始化

[15:14:30 root@yp ~] /usr/local/mysql/bin/mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

十、开机自启

[15:22:07 root@yp ~] echo '/etc/init.d/mysqld start' >> /etc/rc.d/rc.local
[15:22:07 root@yp ~] chmod +x /etc/rc.d/rc.local

猜你喜欢

转载自blog.csdn.net/u014578909/article/details/108725351