[root@hadoop001 ~]# cd /usr/local
[root@hadoop001 local]# tar -xzvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[root@hadoop001 local]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql
[root@hadoop001 local]# mkdir mysql/arch mysql/tmp
创建 mysqladmin 用户及用户组
[root@hadoop001 local]# groupadd -g 101 dba
[root@hadoop001 local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@hadoop001 local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
# 此时切换到 mysqladmin 用户会发现没有正常显示
# 退出该用户然后拷贝环境变量的配置文件到 mysqladmin 用户的家目录
[root@hadoop001 local]# su - mysqladmin
-bash-4.2$ exit
logout
[root@hadoop001 local]# cp /etc/skel/.* /usr/local/mysql
cp: omitting directory ‘/etc/skel/.’
cp: omitting directory ‘/etc/skel/..’
cp: omitting directory ‘/etc/skel/.mozilla’
[root@hadoop001 local]# su - mysqladmin
Last login: Sat Dec 21 22:02:59 CST 2019 on pts/0
[mysqladmin@hadoop001 ~]$
配置 mysqladmin 用户的环境变量
[root@hadoop001 local]# vi mysql/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
#env
export MYSQL_HOME=/usr/local/mysql
export PATH=${MYSQL_HOME}/bin:$PATH
# 将服务文件拷贝到 init.d 目录下,并重命名为 mysql
[root@hadoop001 local]# cp mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
[root@hadoop001 local]# chmod +x /etc/rc.d/init.d/mysql
[root@hadoop001 local]# chkconfig --del mysql
[root@hadoop001 local]# chkconfig --add mysql
[root@hadoop001 local]# chkconfig --level 345 mysql on
执行安装程序,等待安装完成
[root@hadoop001 local]# su - mysqladmin
Last login: Sat Dec 21 22:41:28 CST 2019 on pts/0
[mysqladmin@hadoop001 ~]$ bin/mysqld \
> --defaults-file=/etc/my.cnf \
> --user=mysqladmin \
> --basedir=/usr/local/mysql/ \
> --datadir=/usr/local/mysql/data/ \
> --initialize
查看生成的临时密码,启动 MySQL 服务
# 查看生成的临时密码
[mysqladmin@hadoop001 data]$ cat data/hostname.err | grep password
2019-12-21T14:43:21.346940Z 1 [Note] A temporary password is generated for root@localhost: g4awpI:eh.YS
# 启动 mysql 服务
[mysqladmin@hadoop001 ~]$ bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 5694
[mysqladmin@hadoop001 ~]$ 2019-12-21T14:49:31.688279Z mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
2019-12-21T14:49:31.740739Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysqladmin@hadoop001 ~]$ service mysql status
SUCCESS! MySQL running (6511)
进入命令行,修改临时密码
[mysqladmin@hadoop001 ~]$ mysql -uroot -p'g4awpI:eh.YS'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.11-log
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
# 使用新密码重新登录
[mysqladmin@hadoop001 ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.7.11-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)
从节点 MySQL 安装注意事项
从节点 MySQL 安装步骤与主节点基本一致,需要注意的是 my.cnf 文件中的 server-id 不能重复