MysqL tar 源�a��g安�b操作
在下述的操作系统为CentOS 7.2,MysqL版本为MysqL-5.7.17
1.安�b前�M行依�包安�b
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel openssl openssl-devel pcre pcre-devel
2.下载源码包
2.1 建议到官方网站下载http://dev.MysqL.com/downloads/MysqL/,选择“Source Code”。下载的过程,需要注册一个Oracle账户,如果有直接登录就好
2.2 提供一个下载地址:http://101.96.10.47/dev.MysqL.com/get/Downloads/MysqL-5.7/MysqL-boost-5.7.17.tar.gz
或者https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
新版本的源码增加了boost库,如果你下的源码里面没有需要下载这个库,否则会报错,故需�M行下�d
groupadd -r MysqL
4.�M入安�b步�E
tar -zvxf MysqL-boost-5.7.17.tar.gz
cd MysqL-5.7.17
mkdir -p /www/MysqL-data
mkdir -p /www/MysqL-logs
mkdir -p /www/MysqL-temp
�M行�A��g
cmake -DCMAKE_INSTALL_PREFIX=/www/MysqL \
-DMysqL_DATADIR=/www/MysqL-data \
-DMysqL_UNIX_ADDR=/www/MysqL/MysqL.sock \
-DWITH_BOOST=/www/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1
上述配置解释:
-DCMAKE_INSTALL_PREFIX=/www/MysqL //设置安装目录
-DMysqL_DATADIR=/www/MysqL/data //设置数据库存放目录
-DMysqL_UNIX_ADDR=/www/MysqL/MysqL.sock //设置UNIX socket目录
-DDEFAULT_CHARSET=utf8mb4 //设置默认字符集
-DDEFAULT_COLLATION=utf8mb4_general_ci //设置默认校对规则
-DWITH_INNOBASE_STORAGE_ENGINE=1 //添加InnoDB引擎支持
-DSYSCONFDIR=/etc //设置my.cnf配置文件的所在目录,默认为安装目录,�]有的�,後期可添加一份至此
�M行��g安�b
make && make install
#安装完成后清理一下零时文件
make clean
设置启动脚本,开机自启动(即��MysqL做成服��)
cp /www/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
cp /www/MysqL/bin/MysqLd /usr/bin/MysqLd
#授予可执行的权限
chmod +x /etc/init.d/MysqLd
#设置为开机启动
systemctl enable MysqLd
chown -Rf MysqL:MysqL /www/MysqL
chown -Rf MysqL:MysqL /www/MysqL-data
chown -Rf MysqL:MysqL /www/MysqL-logs
chown -Rf MysqL:MysqL /www/MysqL-temp
#参考,具体里面的参数说明,请自行�W上搜索
[MysqLd]
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
skip-external-locking
skip-name-resolve
user = MysqL
port = 3306
basedir = /www/MysqL
datadir = /www/MysqL-data
tmpdir = /www/MysqL-temp
# server_id = .....
socket = /www/MysqL/MysqL.sock
log-error = /www/MysqL-logs/MysqL_error.log
pid-file = /www/MysqL-data/MysqL.pid
open_files_limit = 10240
back_log = 600
max_connections=500
max_connect_errors = 6000
wait_timeout=605800
#open_tables = 600
#table_cache = 650
#opened_tables = 630
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 300
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 16k
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
lower_case_table_names=1(不�^分大小���O定)
default-storage-engine = INNODB
innodb_buffer_pool_size = 1G
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_flush_method = O_DIRECT
#####################
long_query_time= 2
slow-query-log = on
slow-query-log-file = /www/MysqL-logs/MysqL-slow.log
[MysqLdump]
quick
max_allowed_packet = 32M
character_set_server = utf8
[MysqLd_safe]
log-error=/var/log/MysqLd.log
pid-file=/var/run/MysqLd/MysqLd.pid
character_set_server = utf8
�湓]:上述character_set_server = utf8�凫督�Q�y�a���}
添加环境变量 vi /etc/profile
#MysqL env
export PATH=$PATH:/www/MysqL/bin:/www/MysqL/lib
使得�O置文件生效 source /etc/profile
初始化数据库
MysqLd --initialize-insecure --user=MysqL --basedir=/www/MysqL --datadir=/www/MysqL-data
备注:
MysqL之前版本MysqL_install_db是在MysqL_basedir/script下
MysqL 5.7直接放在了MysqL_install_db/bin目录下。
"�Cinitialize"已废弃,生成一个随机密码(~/.MysqL_secret)
"�Cinitialize-insecure"不会生成密码
"�Cdatadir"目录下不能有数据文件
或者使用下列�Z句:
MysqL_install_db --user=MysqL --basedir=/www/MysqL --datadir=/www/MysqL-data
启动数据库
systemctl start MysqLd
查看������B
systemctl status MysqLd
查看MysqL服务进程和端口
ps -ef | grep MysqL
netstat -tunpl | grep 3306
MysqL和Oracle数据库一样,数据库也默认自带了一个root用户(这个和当前Linux主机上的
root用户是完全不搭边的),我们在设置好MysqL数据库的安全配置后初始化root用户的密码。
配制过程中,一路输入 y 就行了。这里只说明下MysqL5.7.17版本中,用户密码策略分成低级
LOW 、中等 MEDIUM 和超强 STRONG 三种,推荐使用中等 MEDIUM 级别!��然也可以不�M行等
��O置
查阅官方文档后发现有以下三种密码策略:
政策 测试执行
0 ---LOW 长度
1 ---MEDIUM 长度; 数字,小写/大写和特殊字符
2 ---STRONG 长度; 数字,小写/大写和特殊字符; 字典文件
�湓]:後�m的用�粝嚓P密�a�⑿枰�按照此����绦校�但是也可以�M行相�P修改
MysqL_secure_installation
除了
Disallow root login remotely
Remove test database and accesss to it 可以��n,
其他都是y
�M入�����
MysqL -uroot -p密�a
��建其他用��
MysqL> create user 'hua'@'localhost' identified by 'hlj123';(後�m可以修改)
�O置存�σ�擎
MysqL> set storage_engine=INNODB;
��建�����
MysqL> create database zgz character set utf8;
查看是否建立成功
MysqL> show databases;
�x予用�粝嚓P�����嘞�
MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.134.100.174' IDENTIFIED BY 'FLM@88' WITH GRANT OPTION;
MysqL> flush privileges;
�z�是否�x予�h程�B接�����嘞抟验_通
MysqL -h 10.134.100.174 -uroot -pFLM@88 zgz
如果�M入����煺f明成功,否�t重��MysqL服�占纯稍俅�L�
若是允�S�用�敉ㄟ^任意服�掌骺蛇M行�B接相�P�����
MysqL> GRANT ALL PRIVILEGES ON databasename.tables TO 'root'@'%' IDENTIFIED BY 'Foxconn@88' WITH GRANT OPTION;
MysqL> flush privileges;
�С瞿阈枰�的�����
MysqLdump -h 10.157.136.134 -uroot -proot --events --ignore-table=MysqL.event --default-character-set=UTF8 jspxcms >zgz.sql
提前建立一��空�����泶娣判枰���入的���,後只需要�绦������入命令
MysqL> use zgz;
MysqL> source /root/zgz.sql(此��槟惴胖�zgz.sql的存放位置)
确定数据表是否创建成功,即数据文件是否导入成功
MysqL> show tables;
��你需要查看��前密�a策略,可�M行下列操作:
MysqL> show VARIABLES like "%password%"
+---------------------------------------+---------+
| Variable_name | Value |
|---------------------------------------+---------|
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| MysqL_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+---------------------------------------+---------+
13 rows in set
Time: 0.030s
修改默认密码策略(当然实际环境是不推荐修改为更低安全策略的)
MysqL> set global validate_password_policy = 0;
validate_password_number_count指定了密码中数据的长度,
validate_password_special_char_count指定了密码中特殊字符的长度,
validate_password_mixed_case_count指定了密码中大小字母的长度。
这些参数,默认值均为1,所以validate_password_length最小值为4,
如果你显示指定validate_password_length的值小于4,尽管不会报错,
但validate_password_length的值将设为4。
修改validate_password_number_count,validate_password_special_char_count,
validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改
另,可通过my.cnf配置文件设置密码策略的级别
vi /etc/my.cnf
[MysqLd]
validate_password_policy=2
validate_password_policy设置MysqL启动的时候,密码策略级别如果设置为3,那么需要指定字典文件
当然你也可以通过my.cnf配置文件关闭validate_password插件
只需要添加一行
validate_password = off
MysqL > show VARIABLES like "validate_password%"
+-----------------+---------+
| Variable_name | Value |
|-----------------+---------|
+-----------------+---------+
0 rows in set
Time: 0.008s
关闭validate_password插件后,就没有了validate_password的一些参数变量。
MysqL新版本默认监听在IPv6的地址族上。更改为监听IPv4地址族,
修改my.cnf添加一行配置:bind-address = 0.0.0.0
重启MysqLd即可
MysqL主主�}�u配置
首先分�e在�商ǚ��掌魃习惭b上述的安�bMysqL的步�E,�_保有�商ǚ��掌骺墒褂�
故����旆�务器环境:
+-------------------+---------------------------------------------------
| |服务器节点1 |服务器节点2 |
+-------------------+------------------------+-------------------------+
|OS |CentOS 7.2 |CentOS 7.2 |
+-------------------+------------------------+-------------------------+
|DB Version |MysqL 5.7.17 |MysqL 5.7.17 |
+-------------------+------------------------+-------------------------+
|HostName |Linux01 |Linux02 |
+-------------------+------------------------+-------------------------+
|IPADDR |172.16.100.69 |172.16.100.70 |
+-------------------+------------------------+-------------------------+
创建复制需要的用户,用户需要slave权限(必要),file,select权限(可选)
MysqL> grant replication slave,file,select on *.* to 'MysqL_sync'@'172.16.100.69' identified by 'FLM88'
MysqL> grant replication slave,select on *.* to 'MysqL_sync'@'172.16.100.70' identified by 'FLM88'
备注:如果想要在Slave上有权限执行 "LOAD TABLE FROM MASTER" 或
"LOAD DATA FROM MASTER" 语句的话,必须授予全局的 FILE 和 SELECT 权限。
上述的�Z句就是�M行了��建了同步����煊��MysqL_sync,密�a及相�P�嘞薜脑O定
分别修改两台服务器上面的配置文件vi /etc/my.cnf
172.16.100.69上的my.cnf:
log-bin=MysqL-bin-db01
server-id=11
log-slave-updates
slave-skip-errors=all
auto_increment_increment=2
auto_increment_offset=1
172.16.100.70上的my.cnf:
log-bin=MysqL-bin-db02
server-id=12
log-slave-updates
slave-skip-errors=all
auto_increment_increment=2
auto_increment_offset=2
�湓]:server-id两个服务器必须配置不一样,
auto_increment_increment配置每个节点中的自动增长字段每次增长的步长
auto_increment_offset配置各个节点自动增长字段的初始值从多少开始
如果我们不设置这两个变量的话,含有自动增长字段的表将在多个服务器上面各自维护,会出现重复的情况导致复制出错。
如上面的设置,A节点自增长的字段产生的值将会是 1,3,5....
而B节点将是2,4,6......
重启两台数据库实例
systemctl restart MysqLd
在两个数据库中执行:show master status;查看主服务器状态:
172.16.100.69(��c1):
MysqL> show master status;
+-----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------------+----------+--------------+------------------+-------------------+
| MysqL-bin-db01.000001 | 1096 | | | |
+-----------------------+----------+--------------+------------------+-------------------+
1 row in set (3.71 sec)
172.16.100.70(��c2):
MysqL> show master status;
+-----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------------+----------+--------------+------------------+-------------------+
| MysqL-bin-db02.000001 | 625 | | | |
+-----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
配置从服务器Slave(两个节点分别执行)
��c1:
MysqL> change master to master_host='172.16.100.70',master_user='MysqL_sync',
master_password='Foxconn88',master_log_file='MysqL-bin-db02.000001',master_log_pos=625;
MysqL> start slave; //启动从服务器复制功能
��c2:
MysqL> change master to master_host='172.16.100.69',master_log_file='MysqL-bin-db01.000001',master_log_pos=1096;
MysqL> start slave; //启动从服务器复制功能
�z查��B:
MysqL>show slave status\G
�湓]:不出���},可以在各自的����熘胁榭吹较嚓P互�涞�master
因�槭窃创a安�b,所以需要��MysqLdump添加�M入服�眨�直接做���接即可
ln /www/MysqL/bin/MysqLdump /usr/bin/MysqLdump
�O定定�r�浞����欤��裼�crontab�绦心_本�M行
#!/usr/bin/env bash
#a
# Author: Zhang Huangbin (zhb@iredmail.org)
# Date: 16/09/2007
KEEP_DAYS='90'
export BACKUP_ROOTDIR="/data0/db_bak/"
export MysqL_USER="root"
export MysqL_PASSWD="FLM@88"
export DATABASES="zgz"
export DB_CHARACTER_SET="utf8"
export PATH='/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin'
export CMD_DATE='/bin/date'
export CMD_DU='du -sh'
export CMD_COMPRESS='bzip2 -9'
export COMPRESS_SUFFIX='bz2'
export CMD_MysqLDUMP='MysqLdump'
export YEAR="$(${CMD_DATE} +%Y)"
export MONTH="$(${CMD_DATE} +%m)"
export DAY="$(${CMD_DATE} +%d)"
export TIME="$(${CMD_DATE} +%H:%M:%S)"
export TIMESTAMP="${YEAR}-${MONTH}-${DAY}-${TIME}"
export BACKUP_SUCCESS='YES'
export BACKUP_DIR="${BACKUP_ROOTDIR}/MysqL/${YEAR}/${MONTH}/${DAY}"
mkdir -p $BACKUP_ROOTDIR
MysqLdump -h 10.134.100.174 -uroot -pFLM@88
--events --ignore-table=MysqL.event --default-character-set=UTF8 zgz>$BACKUP_ROOTDIR$TIMESTAMP.sql
上述只是相��例子,可�M行�m��修改即可使用。
原文链接:https://www.f2er.com/centos/377607.html