#下载安装包
到官网确定一下最新包
https://dev.mysql.com/downloads/mysql/
这里不是为了追求新的,只是因为mysql官网会删掉老的包,不找版本号,下面的全是404
如图最新版本是8.0.13
#!/bin/bash
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-client-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-common-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-devel-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-libs-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-server-8.0.13-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-test-8.0.13-1.el7.x86_64.rpm
版本号自己替换
#卸载自带的libs
[root@yg2q-f01-02-tyss-02 mysql8]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@yg2q-f01-02-tyss-02 mysql8]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm
这里顺序无所谓,报错再跑一边
因为是rpm安装,所以安装路径是默认的,
但是通常系统盘都很小,所以要修改数据目录
cat /etc/my.cnf 内容如下
这里要注意的就是server-id,自己修改一下,主从不能一致
[mysqld]
#basedir= /data/data/mysql/
datadir= /data/data/mysql/data/
port = 3306
socket = /data/data/mysql.sock
log-bin = /data/data/mysql/mysql-bin.log
server-id = 31
max_connections=10000
max_allowed_packet = 30M
character-set-server = utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
default-storage-engine=INNODB
slow_query_log = 1
long_query_time=1
gtid_mode=ON
log-slave-updates=ON
enforce-gtid-consistency=ON
binlog_format=row
[client]
default-character-set= utf8mb4
socket=/data/data/mysql.sock
[mysql]
default-character-set= utf8mb4
socket=/data/data/mysql.sock
因为挂载点是data所以这边的路径是/data/data/
mkdir /data/data/mysql/ -p
chown mysql:mysql /data/data/
[root@YG2Q-F01-01-TYSS-01 data]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@YG2Q-F01-01-TYSS-01 data]# journalctl -xe
12月 12 00:23:48 YG2Q-F01-01-TYSS-01 polkitd[918]: Registered Authentication Agent for unix-process:554296:215483489 (system bus name :1.3775 [/usr/bin/pkttyagent --notify-fd 5 --fallback],
12月 12 00:23:48 YG2Q-F01-01-TYSS-01 systemd[1]: Starting MySQL Server...
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
12月 12 00:23:48 YG2Q-F01-01-TYSS-01 mysqld_pre_systemd[554315]: /usr/sbin/restorecon: lstat(/data/data/mysql/data) failed: No such file or directory
12月 12 00:23:48 YG2Q-F01-01-TYSS-01 mysqld_pre_systemd[554315]: 2018-12-11T16:23:48.926478Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server in progr
12月 12 00:23:50 YG2Q-F01-01-TYSS-01 mysqld_pre_systemd[554315]: 2018-12-11T16:23:50.360363Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fgti9+!>yQ_B
12月 12 00:23:51 YG2Q-F01-01-TYSS-01 mysqld_pre_systemd[554315]: 2018-12-11T16:23:51.437106Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has comp
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.301933Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 10000 (requested 50000)
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.302057Z 0 [Warning] [MY-010141] [Server] Changed limits: max_connections: 9190 (requested 10000)
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.302069Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 400 (requested 4000)
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.549390Z 0 [Warning] [MY-010091] [Server] Can't create test file /data/data/mysql/data/YG2Q-F01-01-TYSS-01.lower-test
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.549444Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 554385
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.552122Z 0 [Warning] [MY-010091] [Server] Can't create test file /data/data/mysql/data/YG2Q-F01-01-TYSS-01.lower-test
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.552132Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /data/data/mysql/d
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: mysqld: File '/data/data/mysql/mysql-bin.index' not found (OS errno 13 - Permission denied)
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.552514Z 0 [ERROR] [MY-010119] [Server] Aborting
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 mysqld[554385]: 2018-12-11T16:23:53.552669Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 systemd[1]: Unit mysqld.service entered failed state.
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 systemd[1]: mysqld.service failed.
12月 12 00:23:53 YG2Q-F01-01-TYSS-01 polkitd[918]: Unregistered Authentication Agent for unix-process:554296:215483489 (system bus name :1.3775, object path /org/freedesktop/PolicyKit1/Auth
[root@YG2Q-F01-01-TYSS-01 data]# ll
总用量 4
drwxr-xr-x. 3 mysql mysql 4096 12月 12 00:23 mysql
[root@YG2Q-F01-01-TYSS-01 data]# cd vim /etc/selinux/
config final/ semanage.conf targeted/ tmp/
[root@YG2Q-F01-01-TYSS-01 data]# vim /etc/selinux/config
[root@YG2Q-F01-01-TYSS-01 data]# setenforce 0
[root@YG2Q-F01-01-TYSS-01 data]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
这里全部贴一下,正常不会遇到这个错误的,
有些人奇怪为什么chown了权限,还是死报没权限,其实是selinux的问题
setenforce 0临时关闭
然后修改
vim /etc/selinux/config中的SELINUX=disabled
永久关闭
service mysqld start
因为我们修改了数据目录,所以不会给默认密码
在如图位置添加skip-grant-tables
重启mysql
先把密码置空
update mysql.user set authentication_string='' where user='root';
flush privileges;
删掉添加的skip-grant-tables
重启mysql
执行下面的命令
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxx';
flush privileges;
创建远程登陆
create user 'root'@'%' identified with mysql_native_password by 'xxxxxx';
授权
grant all privileges on *.* to 'root'@'%' with grant option;
授权slaves
CREATE USER 'slave'@'172.19.203.2' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'172.19.203.2';
flush privileges;
查看master_auto_position点数
show master status;
如图master_auto_position点数为2625
change master to master_host='172.19.203.1',master_user='slave',master_password='xxxxxx',master_auto_position=2625;
- master_host为主节点ip
- master_user创建的供slave同步数据的用户名
- master_password创建的供slave同步数据的用户的密码
- master_auto_position从哪个主节点数开始同步
这里注意一定要设置同步了之后再创建业务账号和库,要不然需要在从库也创建一遍
show slave status \G;
两个no,说明slave进程没有启动
执行完了需要启动slave同步进程
start slave;
show slave status \G;
show slave status\G;
创建业务用户,
密码加密方式一定要是mysql_native_password
create user 'portal'@'%' identified with mysql_native_password by 'xxxxxx';
给用户授权
grant all privileges on video_portal.* to 'portal'@'%' with grant option;
本文详细介绍如何从MySQL官网下载安装包并进行安装,包括卸载旧版本、修改数据目录及SELinux配置,最后完成用户权限设置及主从复制配置。
4106

被折叠的 条评论
为什么被折叠?



