二进制安装mysql

操作系统:Linux centos7     安装版本:mysql-5.7.21
下载地址:wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

1.安装依赖包
yum  install autoconf libaio   libaio-devel -y

2.创建组和用户
groupadd mysql ;useradd -r -g mysql -s /bin/false mysql

3.创建目录及授权
[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.添加环境变量
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile ;source  /etc/profile

5.修改参数文件
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.数据库初始化
cd /usr/local/mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

查看初始密码:cat  /usr/local/mysql/log/liandodb_error.err |grep root

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.使用数据库
mysql -uroot -pefM0GruzV0=<
修改用户密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
flush privileges;

创建用户及授权
create USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
grant all privileges on *.* to 'test'@'%' with grant option;
flush privileges;

二进制安装mariadb

操作系统:Linux centos7     安装版本:mariadb-10.2.25
1.创建用户及数据库安装目录
useradd -r -s /sbin/nologin  -d /data/mysql  mysql 
mkdir /data/mysql

2.解压及授权
[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
软链接修改权限必须加"/"
[root@centos7_2 local]# chown -R root.root  mysql/

3.创建数据库
[root@centos7_2 scripts]# pwd
/usr/local/mysql/scripts
[root@centos7_2 scripts]# ls
mysql_install_db
#mysql_install_db  用于创建数据库的脚本
[root@centos7_2 mysql]# pwd
/usr/local/mysql
[root@centos7_2 mysql]# scripts/mysql_install_db  --datadir=/data/mysql  --user=mysql #必须在/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

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

5.启动服务
[root@centos7_2 support-files]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

6.环境变量配置
[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

源码编译安装mariadb

操作系统: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.创建物理卷
[root@centos7_3 ~]# pvcreate /dev/sda7
  Physical volume "/dev/sda7" successfully created.
查看:
[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.创建逻辑卷
[root@centos7_3 ~]# lvcreate -n mysql -l 100%free vg0
  Logical volume "mysql" created.
查看:
[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

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

二、数据库安装
1.创建用户及授权
[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
如果要重新编译,需要删除CMakeCache.txt该文件
   rm -f CMakeCache.txt
4.安装
make -j 4 && make install && echo -e '\a' &&date

5.准备环境变量
echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
6.生成数据库文件
cd /app/mysql/
scripts/mysql_install_db  --datadir=/data/mysql/ --user=mysql
7.准备配置文件
cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
vim /etc/my.cnf
datadir=/data/mysql
8.准备启动脚本
cp /app/mysql/support-files/mysql.server  /etc/init.d/mysqld
9.启动服务
chkconfig --add mysqld
chkconfig --list
systemctl start mysqld

©著作权归作者所有:来自51CTO博客作者小怪獣55的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. Dynamics 365利用HTML页面创建实体记录并同步上传附件
  2. 利用Azure虚拟机安装Dynamics 365 Customer Engagement之九:新建
  3. 利用Azure虚拟机安装Dynamics 365 Customer Engagement之十:为SQ
  4. Google Guice之牛刀小试
  5. 使用代码检查Dynamics 365中的备用键状态
  6. Kubernetes使用 S3FS 将 AWS S3 作为持久性存储
  7. 监控系统项目实施--安装与部署--添加一台主机
  8. vscode软件与插件安装配置、markdown语法、Emmet插件使用方式
  9. 监控系统项目实施--安装与部署—zabbix安装

随机推荐

  1. [置顶] android按键功能的拓展
  2. Android的国际化
  3. 2019-12-16 Android中的动画
  4. Ubantu下搭建Android CTS 兼容性测试环境
  5. Android消息机制浅析——面试总结
  6. Android内核的简单分析
  7. @+id/和android:id的区别
  8. Android 简单的代码混淆
  9. Android适配全攻略(学习笔记总结)
  10. Android之——自定义TextView