mysql 5.7版本的二进制安装方法
export LANG=en_US
Centos7 X64
注意:安装完centos7 后,linux需要指定新建一个用户,要求密码强度很高,才能通过,安装系统完成。
--------------------------------------------------------------
所需文件下载地址:https://dev.mysql.com/downloads/mysql/
linux 环境配置:
#安装环境
cat /etc/issue
uname -a
cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.9 (Santiago)
//查看系统的版本
1. 安装centos 选择语言:english / U.S.English 防止乱码
echo $LANG
vi /etc/sysconfig/i18n
echo LANG=zh_CN.gbk
locale -a |grep en
export LANG=en_US
注意:修改了主机名后========================
[root@DB-mysql1-c mysql]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.1.11 DB-manger2
[root@DB-mysql1-z mysql]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=DB-mysql1-b
[root@DB-mysql1-c mysql]# hostname DB-mysql1-b
[root@DB-mysql1-c mysql]# hostname
DB-mysql1-b
==============================================
SELINUX
vi /etc/sysconfig/selinux
(本来是:SELINUXTYPE=targeted )
SELINUX=disabled
[root@ums-data mysql]# setenforce 0 (关闭沙盒!)
[root@ums-data mysql]# getenforce
Disabled
防火墙
[root@ums-data mysql]# chkconfig iptables off
[root@ums-data mysql]# iptables -F (清空防火墙默认规则)
[root@localhost ~]# service iptables stop
[root@localhost ~]# chkconfig iptables off //禁止开机启动
关闭GNOME 桌面:
[root@localhost ~]# vi /etc/inittab
3 -- 为命令行
5 -- 为桌面
然后重启系统后
#init 3
网卡:
临时关闭,重启网卡没有影响,开机重启之后,该服务又重新启动。所以一般选择永久关闭
/etc/init.d/NetworkManager stop
永久关闭
[root@rac1 named]# chkconfig NetworkManager off
[root@rac1 named]# chkconfig --level 35 NetworkManager off
[root@rac1 named]# systemctl restart network //重启网卡-----------
// 修改网卡---------
[root@rac1 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@rac1 network-scripts]# cat ifcfg-ens256
增加路由规则:
route add -net 172.28.22.0 netmask 255.255.255.0 gw 172.28.20.254 dev eth1
route add -net 172.28.22.0 netmask 255.255.255.0 gw 172.28.20.254 dev eth2
[root@dns~]# cat /etc/resolv.conf
search localdomain
nameserver 114.114.114.114
[root@rac2 ~]# cat /etc/hosts
----------修改swap 分区:------------
以下操作需要root权限。
#cd /usr/
#mkdir swap
#dd if=/dev/zero of=swapfile2 bs=2G count=2
dd if=/dev/zero of=swapfile bs=2M count=1024
这条命令从硬盘里分出一个 2×8G 大小的空间,挂在swapfile上。
#mkswap swapfile
构建swap格式于/usr/swap/swapfile 上
#swapon swapfile
激活swapfile ,加入到swap分区中。
# vi /etc/fstab
在/etc/fstab文件中加入下面这样一行:
/usr/swap/swapfile swap swap defaults 0 0
bs=bytes:同时设置读入/输出的块大小为bytes个字节。
count=blocks:仅拷贝blocks个块,块大小等于ibs指定的字节数。
--------------配置 YUM
[root@ums-data /]# vi /etc/resolv.conf
nameserver 114.114.114.114 (在结尾加上)
---CentOS 6
[root@ums-data /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@ums-data /]# yum makecache --生成缓存
---------------------------------------------------
挂载cdrom,配置本地YUM
# mkdir /mnt/cdrom
# mount /dev/cdrom /mnt
或者
# mount /dev/cdrom /media/cdrom
安装本地光盘yum:
1.检查是否安装了yum
# rpm -qa |grep yum
redhat一般都默认安装了yum。
[rhel-source]
name=localyum
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
#这里指向了Server目录, 如果还要软件, 则还需建立指向Cluster,ClusterStorage,VT的baseurl.
[root@DB-mysql1-z yum.repos.d]# pwd
/etc/yum.repos.d
[root@DB-mysql1-z yum.repos.d]# ls
my.repo redhat.repo
[root@DB-mysql1-z yum.repos.d]# cat my.repo
[name]
name=my new repo
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@DB-mysql1-z yum.repos.d]#
3.清除缓存
[root@kangvcar ~]# yum clean all
[root@kangvcar ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list //列出了3780个包
4.安装测试
#yum -y install gcc
--------------配置网络 YUM
[root@ums-data /]# vi /etc/resolv.conf
nameserver 114.114.114.114 (在结尾加上)
---CentOS 6
[root@ums-data /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@ums-data /]# yum makecache --生成缓存
----安装好linux 系统自带的
[root@localhost bayaim]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
------------------------------------------------------------------
bayaim
1.0 包管理器安装>>>>>>>>>>>>>>>>>>>>>
yum -y install mysql-community-server
bayaim
2.0 二进制安装>>>>>>>>>>>>>>>>>>>>>
--------------创建mysql用户及用户组
--------------创建mysql的安装目录及数据库存放目录
操作步骤:
userdel mysql
groupadd mysql
useradd -d /hom
[root@ rhel5~]# groupadd mysql
useradd -r -g mysql mysql
useradd -d /home/mysql -m mysql
passwd mysql
passwd mysql
输入密码mysql
chown -R mysql:mysql /home/mysql
chmod 755 /home/mysql
[root@bayaim rpm-gpg]# id mysql
-----------------------------------------------
安装二进制包:mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
yum install gcc
yum install ncurses-devel
yum install bison
yum remove libnuma.so.1
yum install make cmake libaio wget -y
yum install numactl.x86_64
yum -y install libaio
解压mysql工具包 :解压到指定目录
[root@www ~]# tar -zxvf /path/to/mysql-version.tar.gz -C /opt
mysql 目录规划:
basedir=/usr/local/mysql
datadir=/mysql/data
datadir=/mysql/data
//存放数据库
socket=/var/lib/mysql/mysql.sock
mkdir -p /mysql/data
mkdir -p /mysql/log
mkdir -p /mysql/undolog
mkdir -p /mysql/redolog
=================================================================
[root@ums-data support-files]# pwd
/usr/local/mysql/support-files
cp support-files/my-default.cnf /etc/my.cnf
cp my-default.cnf /etc/my.cnf //这一步的my-default.cnf 在mysql 5.7 版本中没有发现,需要手动建立
vi /etc/my.cnf
[client]
port = 3306
socket = /mysql/data/mysql.sock
[mysqld]
server_id=0117
port = 3306
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
socket = /mysql/data/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/data
pid-file = /mysql/data/mysql.pid
binlog_format = row
log-bin = /mysql/log/mysql_bin
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 256M
open_files_limit = 65535
##===========slave/master===================
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=mysql
#replicate-do-db=db1
#replicate-do-db = ordersys
log-slave-updates
slave-skip-errors=all
slave-net-timeout=6
binlog-ignore-db=mysql
auto-increment-increment = 2
auto-increment-offset = 2
expire_logs_days = 7
#####=======================[innodb]============================
innodb_page_size = 8192
innodb_buffer_pool_size = 8G
innodb_buffer_pool_dump_pct = 40
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 4
innodb_purge_rseg_truncate_frequency = 128
innodb_page_cleaners = 4
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 128M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 80
innodb_max_undo_log_size = 1G
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:512M:autoextend
innodb_undo_tablespaces=3
innodb_undo_log_truncate = 1
innodb_log_group_home_dir = /mysql/redolog/
innodb_undo_directory = /mysql/undolog/
innodb_undo_logs = 128
binlog_gtid_simple_recovery=1
log_timestamps = SYSTEM
transaction_write_set_extraction=MURMUR32
show_compatibility_56=on
innodb_flush_log_at_trx_commit= 2
sync_binlog = 500
sync_relay_log = 10000
sync_relay_log_info = 10000
sync_master_info = 10000
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=6
master-info-repository=TABLE
relay-log-info-repository=TABLE
log_slave_updates=1
innodb_flush_method=O_DIRECT
#####==================[log]===========================
log_error = /mysql/log/error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql/log/slow.log
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
===================================================================
安装前要卸载mariadb
[root@localhost data]# rpm -qa | grep mysql
[root@localhost data]# rpm -qa | grep mairadb
rpm -e --nodes 卸载
rpm -e --nodeps mysql-server-5.1.73-8.el6_8.x86_64
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
rpm -e --nodeps mysql-5.1.73-8.el6_8.x86_64
rpm -e --nodeps qt-mysql-4.6.2-28.el6_5.x86_64
解压>>>>mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz ,并拷贝到/usr/local/mysql目录下
mkdir -p /usr/local/mysql & tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz & cp -r mysql-5.7.22-linux-glibc2.12-x86_64/* /usr/local/mysql
chmod 755 /home/mysql & chmod 755 /etc/my.cnf & chown -R mysql.mysql /etc/my.cnf & chown -R mysql.mysql /usr/local/mysql & chown -R mysql.mysql /mysql/
ls -l /etc/my.cnf & ls -l /usr/local/mysql
) 初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
2019-05-17T17:48:01.208424+08:00 1 [Note] A temporary password is generated for root@localhost: :ez.d0Yg8NI>
--basedir mysql基础目录
--datadir mysql数据存放目录
注意: 安装时候,datadir=/mysql/data 下必须文件夹为空
出现:以下内容说明正确了
[root@localhost log]# ll -l /mysql/log
total 16
-rw-r-----. 1 mysql mysql 802 Apr 28 14:33 error.log
-rw-r-----. 1 mysql mysql 177 Apr 28 14:33 mysql_bin.000001
-rw-r-----. 1 mysql mysql 33 Apr 28 14:33 mysql_bin.index
-rw-r-----. 1 mysql mysql 191 Apr 28 14:33 slow.log
7)启动数据库
[root@localhost log]# rm -rf mysql_bin.index
[root@localhost log]# cat /dev/null >error.log
[root@localhost log]#
(5)手动启动mysql
[root@ rhel5 mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止
或
[root@DB-mysql1-z mysql]# ps -ef | grep mysql
[root@ rhel5 mysql]# cd /usr/local/mysql
#复制脚本 : cp support-files/mysql.server /etc/init.d/mysqld ---增加mysqld 服务
#增加可执行权限 : chmod +x /etc/init.d/mysqld
#增加至sysV服务 : chkconfig --add mysqld
#开机自启动 : chkconfig --level 35 mysqld on
# chkconfig --list | grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#启动mysql服务 : service mysqld start
#查看启动的mysql进程 : netstat -aux|grep mysql
8) MySQL做成服务,加入开机自启动
vi /etc/init.d/mysqld //修改basedir = '' 修改datadir = '',修改成对应路径
basedir=/usr/local/mysql
datadir=/mysql/data
8) 查看默认密码, 修改数据库初始root密码
[root@localhost log]# grep password /var/log/mysqld.log
2019-05-17T04:17:44.919788+08:00 1 [Note] A temporary password is generated for root@localhost:qt:Ba>rXw8C(
mysqladmin修改新的密码:
[root@www ~]# /usr/local/mysql/bin/mysqladmin -uroot -p'xB(wwJFS%40P' --socket=/data/mysql/mysql.sock password
/usr/local/mysql/bin/mysqladmin -uroot -p'xB(wwJFS%40P' password YiNbAI_4I6QUan
---6.0-添加环境变量------------------------------------------------------------
方法一:
[root@ums-data support-files]# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@ rhel5~]#source /root/.bash_profile
方法二:
[root@query-db data]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
[root@query-db data]# source /etc/profile
service mysqld start
service mysqld stop
#mysqladmin -uroot -proot shutdown
#mysqld_safe --defaults-file=/etc/my.cnf &
9)登陆mysql
[root@www ~]# mysql -uroot -p
password:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'xB(wwJFS%40P' WITH GRANT OPTION;
DELETE FROM mysql.user WHERE user='';
flush privileges;
select Host,User from mysql.user ;
export LANG=en_US
netstat -nutlp | grep 3306
ps -ef |grep mysql
[root@oradata mysql3308]# mysql --socket=/data/mysql3306/mysql.sock -uroot -prootBPY123.#
[root@oradata mysql3308]# mysql -h127.0.0.1 -P 3308 -uroot -p
[root@oradata mysql3308]# mysql --socket=/data/mysql_3306/data/mysql_3306.sock
[root@oradata mysql3308]# mysql -S /data/mysql/mysql.sock
MySQL5.7 加强了安全保障,以上意思是密码不符合安全策略要求,我们输入一个8位或以上长度,复杂一点的密码,比如:
mysql> alter user 'root'@'localhost' identified by 'rootBPY123.#';
//为root添加远程连接的能力。
mysql>use mysql;
mysql>desc user;
mysql> update user set Password = password('root') where User='root';
mysql> select Host,User from mysql.user where User='root';
空用户
mysql>DELETE FROM mysql.user WHERE user='';
mysql>flush privileges;
mysql>exit
grant all privileges on *.* to 'tongbu2'@'10.255.12.%' identified by 'root' with grant option
-----5.7
update mysql.user set authentication_string=password('readonly') where user='123456' ;
关机命令:
1、halt 立刻关机
2、poweroff 立刻关机
3、shutdown -h now 立刻关机(root用户使用)
4、shutdown -h 10 10分钟后自动关机 如果是通过shutdown命令设置关机的话,可以用shutdown -c命令取消重启
重启命令:
1、reboot
2、shutdown -r now 立刻重启(root用户使用)
3、shutdown -r 10 过10分钟自动重启(root用户使用)
4、shutdown -r 20:35 在时间为20:35时候重启(root用户使用) 如果是通过shutdown命令设置重启的话,可以用shutdown -c命令取消重启
查看端口:
lsof -i :3306
netstat -lnt|grep 330
mysql> grant all privileges on *.* to 'bai'@'%' identified by 'bai';
mysql> flush privileges;
select Host,User from user where User='root';
revoke all on *.* from dba@localhost;
select count(*) from processlist;
show full processlist
show variables like 'sql_mode%';
查看隔离级别:
show variables like '%iso%';
show variables like '%auto%';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| autocommit | ON |----自动提交
刷新log日志,自此刻开始产生一个新编号的binlog日志文件
flush logs;
重置(清空)所有binlog日志
reset master;
是否启用了日志
show variables like 'log_%';
怎样知道当前的日志
show master status;
show variables like '%query%log%';
show status like 'open%tables';
手机扫一扫
移动阅读更方便
你可能感兴趣的文章