centos 离线 安装 mysql,centos 安装mysql 两种方式: 离线,在线

1, centos6 安装mysql 5.5

A, 离线安装: rpm包

centos6 mysql5.5 离线包下载: https://dev.mysql.com/downloads/mysql/5.5.html#downloads

【mysql5.5安装后默认没有密码, 比其余的版本方便】html

#1, 删除已安装的mysql服务, 顺序安装新的rpm包

rpm -qa |grep mysql |xargs -n 1 rpm -e --nodeps

whereis mysql |xargs -n 1 rm -rf

whereis mysqld |xargs -n 1 rm -rf

rm -rf /var/lib/mysql

#2,安装mysql5.5

mkdir ~/mysqls

tar -xvf ~/MySQL-5.5.62-1.el6.x86_64.rpm-bundle.tar -C ~/mysqls ; cd ~/mysqls

rpm -ivh MySQL-devel-5.5.62-1.el6.x86_64.rpm --nodeps --force

rpm -ivh MySQL-shared-5.5.62-1.el6.x86_64.rpm --nodeps --force

rpm -ivh MySQL-shared-compat-5.5.62-1.el6.x86_64.rpm --nodeps --force

rpm -ivh MySQL-embedded-5.5.62-1.el6.x86_64.rpm --nodeps --force

rpm -ivh MySQL-client-5.5.62-1.el6.x86_64.rpm --nodeps --force

rpm -ivh MySQL-server-5.5.62-1.el6.x86_64.rpm --nodeps --force

#启动mysql,设置root密码

service mysql start

mysqladmin -u root password '123456'

775e8264c42d465d04ab16782705052f.png

B, 离线安装: 二进制包

前言: mysql yum、apt安装须要联网,而rpm、dpkg安装离线包容易致使依赖问题(由于操做系统版本不一样,致使依赖的环境会有差异),全部使用二进制文件安装是比较理想的

下载依赖包

yum -y install libaio numactl

下载mysql二进制包

1, 使用mysql默认启动参数

##1, 下载安装包到/root下

cd /root

yum -y install libaio wget

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

##2, 准备安装:删除旧的数据

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

[ -e /usr/local/mysql ] && rm -rf /usr/local/mysql*

tar zxvf ~/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

cd /usr/local/

ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql

cd mysql

mkdir mysql-files

chown mysql:mysql mysql-files

chmod 750 mysql-files

##3, 初始化mysql: 差生随机root密码

bin/mysqld --initialize --user=mysql &>/tmp/mysql.pwd

bin/mysql_ssl_rsa_setup

##4, 变量全局化

\cp support-files/mysql.server /etc/init.d/mysql

echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile.d/mysql.sh

source /etc/profile >/dev/null 2&>1

##5, 启动mysql

#bin/mysqld_safe --user=mysql &

chkconfig mysql on

service mysql start

##6, 修改root密码

passwd=$(cat /tmp/mysql.pwd |grep password |awk -F "root@localhost: " '{print $2}')

mysql --connect-expired-password -uroot -p$passwd -e " set password for root@localhost = password('123456')"

echo -e "\033[32m mysql安装成功. \033[0m"

2, 自定义mysql启动参数

[root@test mysql]# ls

inst_mysql.sh mysql8/

[root@test mysql]# ls mysql8/support-files/

libaio-0.3.109-13.el7.x86_64.rpm mysql8 mysqld_multi.server mysql-log-rotate mysql.server

##1, 自定义mysql参数配置

[root@test mysql]# cat mysql8/my.cnf

[mysqlr]

datadir=/usr/local/mysql8/data

socket=/usr/local/mysql8/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/usr/local/mysql8/mysql.err

socket=/usr/local/mysql8/mysql.sock

pid-file=/usr/local/mysql8/mysql.pid

port=33061

#mysqlx-port=33062,此处配置不生效

#2, 修改mysql服务脚本

#此文件是复制的mysql.server,

#a,并法注释掉第239行以parse_server_arguments 开头的方法调用

#b,并在266行添加mysqld_safe 启动参数 $bindir/mysqld_safe --mysqlx-port=$mysqlx_port ...

[root@eadage mysql]# cat mysql8/support-files/mysql8 |head -30

#!/bin/sh

# Comments to support chkconfig on RedHat Linux

# chkconfig: 2345 64 36

# description: A very fast and reliable SQL database engine.

basedir=/usr/local/mysql8

datadir=$basedir/data

mysqlx_port=33062

lockdir='/var/lock/subsys'

lock_file_path="$lockdir/mysql8"

mysqld_pid_file_path=/usr/local/mysql8/mysql.pid

[root@test mysql]# find mysql8/ -maxdepth 1

mysql8/

mysql8/support-files

mysql8/lib

mysql8/include

mysql8/share

mysql8/my.cnf

mysql8/man

mysql8/bin

mysql8/docs

mysql8/run

mysql8/var

[root@test mysql]# cat inst_mysql.sh

#!/bin/bash

set -x

basedir=/usr/local/mysql8

mysql_data=$basedir/data

mysql_tmp=$basedir/tmp

mysql_sock=$basedir/mysql.sock

ss -nltp |grep 3306[1-2]

[ $? -eq 0 ] && [ -e /etc/init.d/mysql8 ] && service mysql8 stop

rm -rf $basedir

cp -r mysql8 $basedir

#1, data dir: data, tmp

[ ! -e $mysql_data ] && mkdir $basedir/{data,tmp} && touch $basedir/mysql.{err,pid}

#2, add user mysql

useradd -r -d $basedir mysql

rpm -Uvh $basedir/support-files/*.rpm --nodeps

#3, change privileges

sudo chown -R mysql:mysql $basedir

$basedir/bin/mysqld --initialize-insecure --user=mysql \

--datadir=$basedir/data --socket=$mysql_sock \

--tmpdir=$mysql_tmp

#4, set params

#$basedir/bin/mysqld_safe --mysqlx-port=33062 --defaults-file=$basedir/my.cnf

cp $basedir/support-files/mysql8 /etc/init.d/

chkconfig mysql8 on

service mysql8 start

#5,set root passwd for mysql #set password for 'root'@'localhost' ='abc123123'

sleep 3

echo "alias mysql='$basedir/bin/mysql --socket=/usr/local/mysql8/mysql.sock'" >>~/.bash_profile

echo "alias mysql='$basedir/bin/mysql --socket=/usr/local/mysql8/mysql.sock'" >>/etc/profile

alias mysql="$basedir/bin/mysql --socket=/usr/local/mysql8/mysql.sock"

mysql -uroot -e " set password='abc123123' "

mysql -uroot -pabc123123 -e "show databases"

C, 在线安装

#1, 删除已安装的mysql服务, 顺序安装新的rpm包

rpm -qa |grep mysql |xargs -n 1 rpm -e --nodeps

whereis mysql |xargs -n 1 rm -rf

whereis mysqld |xargs -n 1 rm -rf

rm -rf /var/lib/mysql

yum -y install wget

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

rpm -ivh mysql-community-release-el6-5.noarch.rpm

yum list |grep mysql

yum -y install mysql-server mysql mysql-devel

#2, 启动服务,修改root密码

service mysqld start

service mysqld status

mysqladmin -u root password 123456

db2032faa56304f73c7a539db00d9af7.png

2, centos7 安装 mysql 5.5

在线安装

wget -c https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

yum -y install mysql mysql-server

3, mysql配置文件:my.cnf

[test@docker ~]$ rpm -ql MySQL-server |grep etc

/etc/init.d/mysql

/etc/logrotate.d/mysql

/etc/my.cnf

/etc/my.cnf.d

############ 经常使用配置项 ###########

[test@docker ~]$ cat /etc/my.cnf

[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

bind-address = 0.0.0.0

#port = 3306

#socket = /var/lib/mysql/mysql.sock

##lower_case_table_names=1

character-set-server = utf8

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

transaction-isolation = READ-COMMITTED

# Disabling symbolic-links is recommended to prevent assorted security risks;

# to do so, uncomment this line:

symbolic-links = 0

key_buffer_size = 32M

max_allowed_packet = 32M

thread_stack = 256K

thread_cache_size = 64

query_cache_limit = 8M

query_cache_size = 64M

query_cache_type = 1

max_connections = 550

expire_logs_days = 10

max_binlog_size = 100M

#log_bin should be on a disk with enough free space.

#Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your

#system and chown the specified folder to the mysql user.

log_bin=/var/lib/mysql/mysql_binary_log

#In later versions of MySQL, if you enable the binary log and do not set

#a server_id, MySQL will not start. The server_id must be unique within

#the replicating group.

server_id=1

binlog_format = mixed

read_buffer_size = 2M

read_rnd_buffer_size = 16M

sort_buffer_size = 8M

join_buffer_size = 8M

# InnoDB settings

innodb_file_per_table = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 64M

innodb_buffer_pool_size = 4G

innodb_thread_concurrency = 8

innodb_flush_method = O_DIRECT

innodb_log_file_size = 512M

[mysqld_safe]

#log-error=/usr/local/mysql8/mysql.err

#socket=/usr/local/mysql8/mysql.sock

#pid-file=/usr/local/mysql8/mysql.pid

#port=3306

sql_mode=STRICT_ALL_TABLES

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值