這里使用的mysql是 mysql-5.7.16
將下載下來的mysql 安裝tar包下載解壓這就不用多說了,
ps:(mysql-5.7.16-linux-glibc2.5-x86_64 這名字太長了,我把他改為mysql-5.7.16)
首先
(1)配置環境變量
############mysql#############
export PATH=$PATH:/usr/local/development/mysql/mysql-5.7.16/bin
(2)新增mysql的用戶和組
[root@node1 development]# groupadd mysql
[root@node1 development]# useradd -r -g mysql mysql
//修改mysql的目錄權限
[root@node1 development]# chown -R mysql mysql /usr/local/development/mysql/mysql-5.7.16/
(3)修改mysql安裝目錄中的 support-files/mysql.server 文件,設置mysql的安裝目錄 和 mysql的數據存儲目錄
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
//mysql的安裝目錄
basedir=/usr/local/development/mysql/mysql-5.7.16
//mysql的數據存儲目錄
datadir=/usr/local/development/mysql/mysqlData
(4)初始化數據庫
[root@node1 bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/development/mysql/mysql-5.7.16 --datadir=/usr/local/development/mysql/mysqlData
2017-06-05 17:44:50 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-06-05 17:44:55 [WARNING] The bootstrap log isn't empty:
2017-06-05 17:44:55 [WARNING] 2017-06-05T09:44:51.057443Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-06-05T09:44:51.075095Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-06-05T09:44:51.075137Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
我們的MySQL存儲目錄已經生成數據了
(5)啟動MySQL(發現報錯)
[root@node1 support-files]# ./mysql.server start
Starting MySQL.touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 169: /var/log/mariadb/mariadb.log: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory
ERROR! The server quit without updating PID file (/usr/local/development/mysql/mysqlData/node1.pid).
我們確實是沒有/var/log/mariadb/mariadb.log 這個目錄,這個是因為你沒有指定他的配置文件的話,他會默認找到/etc/my.cnf 這個配置文件,因為我們修改了mysql的數據存儲目錄。
將/etc/my.cnf 刪掉,再次啟動
[root@node1 support-files]# rm -f /etc/my.cnf
[root@node1 support-files]# ./mysql.server start
Starting MySQL.. SUCCESS!
(6)查詢MySQL自動生成的root密碼
[root@node1 support-files]# more /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-06-05 17:44:50
N5*gFyur1LbC //這里就是
(7)在bin目錄下 登錄MySQL(將自動生成的密碼粘貼上去即可)
[root@node1 bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16
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.
(8)修改MySQL的root密碼(你肯定不想使用自動生成的那個密碼吧)
mysql> set password=password('mysql123');//設置密碼
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> alter user 'root'@'localhost' password expire never//將密碼應用於root用戶
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges//刷新權限的列表
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> exit//退出
Bye
重新登錄,試一試剛才修改的密碼是否生效,當然你們是看不見輸入密碼的,我這里已經生效了
上面是MySQL的搭建過程,我是使用MySQL來存儲hive的元數據,而MySQL不允許使用root用戶遠程登錄,所以我新建hive用戶
mysql> create user 'hive'@'%' identified by 'hive123';//創建用戶名和密碼
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'hive'@'%';//賦予hive用戶所有權限,'%'表示任何地址都可以通過hive用戶連接mysql,如果你想限制可以加入你的ip
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;//刷新權限列表
Query OK, 0 rows affected (0.00 sec)
mysql> create database hivedb;//創建數據庫
Query OK, 1 row affected (0.00 sec)
查看創建的數據庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hivedb |
| mysql |
| performance_schema |
| sys |
+--------------------+