离线编译安装mysql-5.6.26

一键脚本离线编译安装mysql-5.6.26

准备工作

先准备好要离线编译的源码包
cmake:https://cmake.org/download/
mysql:https://www.mysql.com/downloads/

编译目录在/usr/local/src/目录下,存放对应的编译压缩包
脚本同解压后文件在同一目录下:  /usr/local/src/

离线编译安装mysql-5.6.26_第1张图片

执行脚本等待十五分钟即可编译安装完毕:

[root@zabbix src]# cat mysql.sh
#!/bin/bash
echo "请输出对应的解压后的 cmake mysql 名称   例如:   cmake-2.8.8       mysql-5.6.26"
read -p "please input cmake.tar  name :      "     cmake
read -p "please input mysql.tar  name :      "     mysql

yum install -y gcc gcc-c++ libxml2-devel openssl-devel bzip2-devel libjpeg-turbo-devel ncurses-devel net-snmp-libs libevent libtool-ltdl &> /dev/null
yum remove -y mysql &> /dev/null
cd $cmake
./configure&&make && make install &> /dev/null
cd /usr/local/src/
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
mkdir /mydata/data -p
chown -R mysql.mysql /mydata/data
cd $mysql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make&&make install &> /dev/null
cd /usr/local/src/
chgrp -R mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysqldata/
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sed -i '26a innodb_file_per_table = 1' /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
chkconfig --add mysqld
echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh 
source /etc/profile.d/mysql.sh 
echo '/usr/local/mysql/lib' > /etc/ld.so 
.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include/ /usr/include/mysql
service mysqld start

常用mysql命令操作:

连接Mysql:
mysql -h 127.0.0.1 -u root -p123456
退出:
ctrl + c  or  exit

修改密码:
mysqladmin -u root -p123456 password pengge666
mysql> set password for root@localhost = password('pengge666');
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
首先登录MySQL 
mysql> use mysql; 
mysql> update user set password=password('pengge666') where user='root' and host='localhost'; 
mysql> flush privileges;

查看所有数据库:
mysql> show databases;
查看当前数据库的所有表:
mysql> use test;
mysql> show tables;

创建数据库:
mysql> create database test;
mysql> create database zabbix character set utf8 collate utf8_bin;

创建数据表:
mysql> create table pengge (
    -> pengge_id   varchar(20),
    -> pengge_date date
    -> );
Query OK, 0 rows affected (5.34 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| pengge         |
| users          |
+----------------+
2 rows in set (0.00 sec)

使用show来查看标准的创建sql语句:
mysql> show create table pengge;
+--------+----------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                           |
+--------+----------------------------------------------------------------------------------------------------------------------------------------+
| pengge | CREATE TABLE `pengge` (
  `pengge_id` varchar(20) DEFAULT NULL,
  `pengge_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+--------+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.08 sec)

mysql> 

insert增加数据sql:
mysql> insert into pengge(pengge_id,pengge_date) values(66,20200703),(99,20200703);
Query OK, 2 rows affected (0.79 sec)
Records: 2  Duplicates: 0  Warnings: 0

查看所有表内容:
mysql> select * from pengge;
+-----------+-------------+
| pengge_id | pengge_date |
+-----------+-------------+
| 66        | 2020-07-03  |
| 99        | 2020-07-03  |
+-----------+-------------+
2 rows in set (0.00 sec)
查看一行表内容:
mysql> select * from pengge limit 1;

删除数据库、表:
mysql> drop database test;
mysql> drop table test;

update修改数据sql:
将pengge_id内所有69的数据修改为66
mysql> update pengge set pengge_id=(66) where pengge_id=(69);


备份数据库:
mysqldump -u root -ppengge test > test-database.sql
mysqldump -h 127.0.0.1 -u root -p123456 --database test pengge  > 指定test库的指定pengge数据表.sql
mysqldump -u root -ppengge --all-databases > 导出全部数据库.sql

还原数据库:
mysql -u root -ppengge < ./test-database.sql 

查看数据库当前正在连接用户:
show full processlist;

查看数据库最大连接数并修改:
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> set GLOBAL max_connections = 200;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 200   |
+-----------------+-------+
1 row in set (0.00 sec)

最后分享一个批量挂载磁盘的脚本:

cat ./ecs_disk.sh

#!/bin/sh
#****************************************************************#
# ScriptName: ecs_disk.sh
# Create Date: 2017-03-29
# Use For: for pengge ecs centos 7.x
# Modify Date: 2017-03-29
# Function:
#***************************************************************#

disk_name="vdb"
ecs_disk="/dev/$disk_name"
log="/tmp/mount_info_data.log"
mount_on="/data"

fdisk -l | grep $disk_name &> /dev/null
[ $? -ne 0 ] && echo "no $disk_name" && exit 255

init_disk(){
    mkfs.ext4 $ecs_disk
    mount -t  ext4  $ecs_disk $mount_on      
    df -h | grep ${mount_on} 
}

check_hw_stat(){
    /usr/sbin/blkid |grep  -q  ${ecs_disk}*
    if [ $? -ne 0 ];then 
	echo "Start format $ecs_disk"
	init_disk &>$log
	[ $? -eq 0 ] && echo "Format & mount $ecs_disk Success" ||  echo "Format & mount $ecs_disk Failed"
    else
	echo "Please Check $ecs_disk Fortmat. It has been formatted."  && exit  255
    fi
}

install_fstab(){
    file="/etc/fstab"
    cp $file ${file}_bak_`date "+%F-%T"`
    echo "$(blkid $ecs_disk | cut -d' ' -f2 | sed 's/\"//g')  ${mount_on} ext4 defaults 0 0" >> $file
}

check_mount_fun(){
    [ ! -r ${mount_on} ] && mkdir ${mount_on} && chown -R admin.admin ${mount_on}
}


main(){
   check_mount_fun &>$log
   check_hw_stat 
   install_fstab &>$log
}

main

学无止境,使劲学,使劲学,努力让自己成为让自己都羡慕的人~~~O(∩_∩)O

你可能感兴趣的:(运维)