【完全分布式Hadoop】(六)MySQL5.7服务端安装,DBA权限设置以及客户端配置

Hadoop admin 2年前 (2018-10-23) 122次浏览 0个评论 扫描二维码

MySQL简单使用一、条件查询
MySQL简单使用二、join使用

一、 下载MySQL5.7

先检查mysql是否已经存在:
ps -ef|grep mysqld
rpm -qa |grep -i mysql #如果有mysql-lib的rpm先不要卸载
查看系统是否有默认安装的mariadb,如果有,和前边的openjdk一样卸载掉
rpm -qa | grep mariadb

rpm -e --nodeps `rpm -qa | grep mariadb`

下载地址:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
如需下载5.7最新版,在官方网站找到MySQL Community选择如下选项

二、 解压mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
cd /usr/local/mysql
mkdir arch data tmp

三、 添加组dba和用户mysqladmin

groupadd -g 101 dba
useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
一般不需要设置mysqladmin的密码,直接从root切换
查看用户组id
id mysqladmin

此时su mysqladmin会出现如下情况,需要进行下一步的操作

copy 环境变量配置文件至mysqladmin用户的home目录中/usr/local/mysql:
cp /etc/skel/.* /usr/local/mysql
添加MYSQL_HOME:

vi /usr/local/mysql/.bashrc
export MYSQL_BASE=/usr/local/mysql
export PATH=${MYSQL_BASE}/bin:$PATH

四、 创建mysql的配置文件/etc/my.cnf

MySQL启动时,配置文件的默认查找路径:
/etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> --defaults-extra-file->~/my.cnf
我们这里直接在/etc/my.cnf中配置,配置内容如下:
cd /etc/
touch my.cnf
vi my.cnf

[client]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock
default-character-set=utf8mb4

[mysqld]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock


skip-slave-start


skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M

table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600

# Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 32 

#isolation level and default engine 
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED

server-id  = 1739
basedir     = /usr/local/mysql
datadir     = /usr/local/mysql/data
pid-file     = /usr/local/mysql/data/hostname.pid

#open performance schema
log-warnings
sysdate-is-now

binlog_format = ROW
log_bin_trust_function_creators=1
log-error  = /usr/local/mysql/data/hostname.err
log-bin = /usr/local/mysql/arch/mysql-bin
expire_logs_days = 7

innodb_write_io_threads=16

relay-log  = /usr/local/mysql/relay_log/relay-log
relay-log-index = /usr/local/mysql/relay_log/relay-log.index
relay_log_info_file= /usr/local/mysql/relay_log/relay-log.info

#need to sync tables
replicate-wild-do-table=omsprd.%
replicate_wild_do_table=wmsb01.%
replicate_wild_do_table=wmsb02.%
replicate_wild_do_table=wmsb03.%
replicate_wild_do_table=wmsb04.%
replicate_wild_do_table=wmsb05.%
replicate_wild_do_table=wmsb06.%
replicate_wild_do_table=wmsb07.%
replicate_wild_do_table=wmsb08.%
replicate_wild_do_table=wmsb08.%
replicate_wild_do_table=wmsb09.%
replicate_wild_do_table=wmsb10.%
replicate_wild_do_table=wmsb11.%
replicate_wild_do_table=wmsb27.%
replicate_wild_do_table=wmsb31.%
replicate_wild_do_table=wmsb32.%
replicate_wild_do_table=wmsb33.%
replicate_wild_do_table=wmsb34.%
replicate_wild_do_table=wmsb35.%
log_slave_updates=1
gtid_mode=OFF
enforce_gtid_consistency=OFF

# slave
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=4
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

#other logs
#general_log =1
#general_log_file  = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave
sync_binlog = 500


#for innodb options 
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend

innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 4
innodb_log_file_size = 1G
innodb_log_buffer_size = 200M

innodb_buffer_pool_size = 8G
#innodb_additional_mem_pool_size = 50M #deprecated in 5.6
tmpdir = /usr/local/mysql/tmp

innodb_lock_wait_timeout = 1000
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 2

innodb_locks_unsafe_for_binlog=1

#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on

#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1

[mysqldump]
quick
max_allowed_packet = 128M

[mysql]
no-auto-rehash
default-character-set=utf8mb4

[mysqlhotcopy]
interactive-timeout

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

my.cnf中需要修改一下参数,这个参数是指MySQL的内存,我这里规划的8G:
innodb_buffer_pool_size = 8G
具体该配置多少请自行配置,用free -m查看剩余内存:

五、 修改权限

chown mysqladmin:dba /etc/my.cnf
chmod 640 /etc/my.cnf
查看my.cnf权限:
ll my.cnf

修改/usr/local/mysql权限:
chown -R mysqladmin:dba /usr/local/mysql
chmod -R 755 /usr/local/mysql
查看用户目录是否生效:
su - mysqladmin

六、 配置服务及开机自启动

root权限下:

[root@hadoop004 ~]# cd /usr/local/mysql
#将服务文件拷贝到init.d下,并重命名为mysql
[root@hadoop004 mysql]#
cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执行权限
[root@hadoop004 mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[root@hadoop004 mysql]# chkconfig --del mysql
#添加服务
[root@hadoop004 mysql]# chkconfig --add mysql
[root@hadoop004 mysql]# chkconfig --level 345 mysql on

七、 安装libaio及安装mysql的初始db

检查libaio-0.3.109-13.el7.x86_64是否存在,如果存在,则不需要安装,如果不存在请安装:

[root@hadoop004 mysql]# yum -y install libaio
进入mysqladmin用户:
[root@hadoop004 mysql]# sudo su - mysqladmin
初始化MySQL:

[mysqladmin@hadoop004 ~]$ bin/mysqld \
--defaults-file=/etc/my.cnf \
--user=mysqladmin \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--initialize

查看临时密码:

[mysqladmin@hadoop004 ~]$ cat /usr/local/mysql/data/hostname.err |grep password
2018-11-02T10:01:57.111611Z 1 [Note] A temporary password is generated for root@localhost: AUO24;Jq22(W

如果初始化未成功可以查看/usr/local/mysql/data/hostname.err内容,修改对应配置后,删除arch内容和data内容,然后重新初始化:
rm -rf arch/* data/*

八、 启动mysql

[mysqladmin@hadoop004 data]$ /usr/local/mysql/bin/mysqld_safe \
--defaults-file=/etc/my.cnf &

九、登录及修改用户密码

登录MySQL:
[mysqladmin@hadoop004 data]$  mysql -uroot -p'AUO24;Jq22(W'
修改密码:
mysql> alter user root@localhost identified by '123456';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

十、重启、测试密码是否修改成功

[mysqladmin@hadoop004 data]$ service mysql restart
[mysqladmin@hadoop004 ~]$ mysql -uroot -p123456

十一、设置root使用mysql以及设置hadoop005客户端

1)在服务端hadoop004中:

如果想在root权限下就可以登录MySQL,只需要给root添加上MySQL的环境变量即可:

[root@hadoop004 package]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@hadoop004 package]# source /etc/profile


将MySQL复制到hadoop005:
[root@hadoop004 package]# scp /usr/local/mysql root@hadoop005:/usr/local/
2)在客户端hadoop005中,root权限下配置环境变量:

[root@hadoop005 package]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@hadoop005 package]# source /etc/profile
[root@hadoop005 package]# mysql -uroot -hhadoop004 -p123456


codeobj , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:【完全分布式Hadoop】(六)MySQL5.7服务端安装,DBA权限设置以及客户端配置
喜欢 (0)
[a37free@163.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址