1.检查系统是否有安装过的mysql,需要卸载干净
#rpm -qa|grep -i mysql
mysql-server-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-devel-5.1.71-1.el6.x86_64
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-libs-5.1.71-1.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
#rpm -e mysql-server-5.1.71-1.el6.x86_64 --nodeps
#rpm -e mysql-5.1.71-1.el6.x86_64 --nodeps
#rpm -e mysql-devel-5.1.71-1.el6.x86_64 --nodeps
#rpm -e qt-mysql-4.6.2-26.el6_4.x86_64 --nodeps
#rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
#rpm -e perl-DBD-MySQL-4.013-3.el6.x86_64 --nodeps
2.创建mysql用户组和用户,data目录及其用户目录
#userdel mysql #删除用户
#groupdel mysql #删除用户组名
#mkdir /home/mysql #在home文件夹下创建文件夹mysql
#mkdir /home/mysql/data #在mysql文件夹下创建文件夹data
#groupadd mysql #创建一个名为mysql的用户组
#useradd -g mysql -d /home/mysql mysql #在用户组下创建用户
会报如下警告
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
处理如下:
#cp /etc/skel/.bash_profile /home/mysql
#cp /etc/skel/.bashrc /home/mysql
#cp /etc/skel/.bash_logout /home/mysql
3.解压软件
#tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar
#cd mysql-5.7.17-linux-glibc2.5-x86_64
#mv * /home/mysql
4.初始化mysql数据库
#./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize --lc_messages_dir=/home/mysql/share --lc_messages=en_US
注意:5.7的版本中已经不在使用mysql_install_db
[ERROR] Can‘t find error-message file ‘/home/mysql/share/errmsg.sys‘. Check error- message file location and ‘lc-messages-dir‘ configuration directive.
是由于没有这和两个系统变量有关,lc_messages_dir andlc_messages, 正常默认是没有问题。 这里我们显式指定一下。重新初始化
5.检测下是否能启动mysql服务
刚刚我用的是/home/mysql为mysql的安装目录basedir, 则在启动服务时会出现如下错误:
[[email protected] mysql]# ./support-files/mysql.server start
./support-files/mysql.server: line 271: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn‘t find MySQL server (/usr/local/mysql/[FAILED]ld_safe)
由上面可知mysql的tar.gz安装包的默认安装目录为/usr/local/mysql,
这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径
# vim support-files/mysql.server
--------------------------
...
basedir=/home/mysql
datadir=/home/mysql/data
...
--------------------------
# ./support-files/mysql.server start
start Starting MySQL.. OK!
6.创建软连接
# ln -s /home/mysql/bin/mysql /usr/bin/mysql
7.创建配置文件
将默认的生成的my.cnf备份
# mv /etc/my.cnf /etc/my.cnf.bak
进入mysql的安装目录支持文件目录
# cd /home/mysql/support-files
拷贝配置文件模板为新的mysql配置文件
# cp my-default.cnf /etc/my.cnf
设置编码,可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行.
# vim /etc/my.cnf
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
#key_buffer = 16M
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
max_connections = 550
#log_bin=/home/mysql/mysql_binary_log
sql_mode=STRICT_TRANS_TABLES
binlog_format = mixed
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
8.配置mysql服务开机自动启动
# mkdir /var/run/mysqld
# chown -R mysql:mysql /var/run/mysqld
注释掉log_bin ,需要的时候要设置server_id
注释掉key_buffer,保留key_buffer_size
# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld # 拷贝启动文件到/etc/init.d/下并重命令为mysqld
# chmod 755 /etc/init.d/mysqld # 增加执行权限
# chkconfig --list mysqld # 检查自启动项列表中没有mysqld这个,
# chkconfig --add mysqld # 如果没有就添加mysqld:
# chkconfig mysqld on # 用这个命令设置开机启动:
9.初始化mysql用户root密码
#mysql -u root -p
输入之前的随机密码
mysql>SET PASSWORD = PASSWORD(‘123456‘); # PASSWORD()里面的123456 是我设置的新密码,你也可以设置成你的密码
mysql>ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;
mysql>flush privileges;
10.授权所有主机都能用root登陆
grant all on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
11.创建mysql数据库
hive 数据库
create database hive DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
--集群监控数据库
create database amon DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
--hue 数据库
create database hue DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
--oozie 数据库
create database oozie DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
----reports manager
create database rman DEFAULT CHARSET utf8 COLLATE utf8_general_ci;