- 爱易网页
-
MySQL教程
- hive与mysql双机配备
日期:2014-05-16 浏览次数:20947 次
hive与mysql双机配置
因为需要hive需要mysql的DB的支持,又因为我们尽量需要做到mysql的容灾备份,所以我们需要安装2套mysql
mysql安装。一台master ,一台slave
增加用户
userdel mysq
groupadd mysql
useradd -g mysql
安装:
yum install libaio-devel 安装postfix
yum安装 yum install mysql-server mysql-devel
或者
sudo rpm -ivh mysql-libs-5.1.47-4.el6.x86_64
sudo rpm -ivh MySQL-client-5.5.25a-1.el6.x86_64
sudo rpm -ivh MySQL-devel-5.5.25a-1.el6.x86_64
卸载mysql
rpm -qa|grep -i mysql
rpm -ev xxx
停止mysql
sudo service mysqld stop
----------------------
启动mysql
sudo /sbin/chkconfig -add mysql //加入启动服务
sudo /sbin/chkconfig -del mysql
sudo service mysqld restart //重起mysql
sudo service mysqld stop //停止mysql
sudo service mysqld start
我们需要授权访问权限
登陆 mysql -uroot -p 新系统没有密码
修改添加用户和密码
update mysql.user set password=PASSWORD('hive') where user='root';
update mysql.user set password=PASSWORD('hive') where user='hive';
flush privileges;
查看mysql 系统表
use mysql;
select * from user;
需要登陆的client都需要有这个授权
grant all on *.* to hive@192.168.137.118 identified by 'hive';
sudo /usr/bin/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql //检查mysql db是否正常
启动mysql sudo service restart
登陆 mysql -h192.168.137.118 -uroot -phive 和 mysql -h192.168.137.118 -uhive -phive
>quit;
mysql的字符集需要改变
SHOW VARIABLES LIKE 'character_set_%';
>set character_set_client =utf8;
>set character_set_connection=utf8;
>set character_set_database =utf8;
>set character_set_filesystem=utf8;
>set character_set_results =utf8;
>set character_set_server =utf8;
>set character_set_system =utf8;
创建hive 的database
create databases hive;
alter database hive character set utf8; //改变db的字符集
找一个hive的配置表验证一下:show create table hive.TBLS;
配置自己的数据目录
cp -r -a /var/lib/mysql /home/mysql/ //带权限copy数据文件目录到自定义目录下
因为目录权限的问题,mysql的数据目录需要放置在/home/mysql 下,mysql安装过程中应该会自动建立这个目录和用户。
修改mysql配置文件,将数据文件目录移动到自定义的目录
配置文件 sudo vim /etc/rc.d/init.d/mysqld
修改 get_mysql_option mysqld datadir "/home/mysql/datadir/mysql"
配置文件 sudo vim /usr/bin/mysqld_safe
修改
else
#DATADIR=/var/lib/mysql
DATADIR=/home/mysql/datadir/mysql
fi
/etc/my.cnf 是mysql的配置文件
安装好mysql后,在/usr/local/mysql/share/mysql目录下,会有my-huge.cnf, my-medinum.cnf, my-small.cnf
如果你的内存≤64M,则复制/usr/share/mysql/my-small.cnf为/etc/my.cnf
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
如果内存是128M,则复制/usr/share/mysql/my-medium.cnf为/etc/my.cnf
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
如果内存是512M,则复制/usr/share/mysql/my-large.cnf为/etc/my.cnf
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
如果内存是1-2G,则复制/usr/local/share/mysql/my-huge.cnf为/etc/my.cnf
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
[mysqld]
datadir=/home/mysql/datadir/mysql //数据文件目录需要配置成自定义
socket=/home/mysql/datadir/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log //log目录使用系统默认
pid-file=/var/run/mysqld/mysqld.pid
启动之后在建立连接
ln -s /home/mysql/datadir/mysql/mysql.sock /var/lib/mysql/mysql.sock
mysql工具验证mysql是否正常
/usr/bin/mysqld_safe
/usr/bin/mysqlcheck