[[email protected] ~]# cd /usr/local
[[email protected] local]# tar -xzvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql
[[email protected] local]# mkdir mysql/arch mysql/tmp
建立 mysqladmin 使用者及使用者組
[[email protected] local]# groupadd -g 101 dba
[[email protected] 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.
[[email protected] local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
# 此時切換到 mysqladmin 使用者會發現沒有正常顯示
# 退出該使用者然後拷貝環境變量的配置檔案到 mysqladmin 使用者的家目錄
[[email protected] local]# su - mysqladmin
-bash-4.2$ exit
logout
[[email protected] local]# cp /etc/skel/.* /usr/local/mysql
cp: omitting directory ‘/etc/skel/.’
cp: omitting directory ‘/etc/skel/..’
cp: omitting directory ‘/etc/skel/.mozilla’
[[email protected] local]# su - mysqladmin
Last login: Sat Dec 21 22:02:59 CST 2019 on pts/0
[[email protected] ~]$
配置 mysqladmin 使用者的環境變量
[[email protected] 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
[[email protected] local]# cp mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
[[email protected] local]# chmod +x /etc/rc.d/init.d/mysql
[[email protected] local]# chkconfig --del mysql
[[email protected] local]# chkconfig --add mysql
[[email protected] local]# chkconfig --level 345 mysql on
執行安裝程式,等待安裝完成
[[email protected] local]# su - mysqladmin
Last login: Sat Dec 21 22:41:28 CST 2019 on pts/0
[[email protected] ~]$ bin/mysqld \
> --defaults-file=/etc/my.cnf \
> --user=mysqladmin \
> --basedir=/usr/local/mysql/ \
> --datadir=/usr/local/mysql/data/ \
> --initialize
檢視生成的臨時密碼,啟動 MySQL 服務
# 檢視生成的臨時密碼
[[email protected] data]$ cat data/hostname.err | grep password
2019-12-21T14:43:21.346940Z 1 [Note] A temporary password is generated for [email protected]: g4awpI:eh.YS
# 啟動 mysql 服務
[[email protected] ~]$ bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 5694
[[email protected] ~]$ 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
[[email protected] ~]$ service mysql status
SUCCESS! MySQL running (6511)
進入指令行,修改臨時密碼
[[email protected] ~]$ 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 [email protected] 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
# 使用新密碼重新登入
[[email protected] ~]$ 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 不能重複